聊聊线程池的预热

本文主要研究一下线程池的预热

prestartCoreThread

java/util/concurrent/ThreadPoolExecutor.java

复制代码
    /**
     * Starts a core thread, causing it to idly wait for work. This
     * overrides the default policy of starting core threads only when
     * new tasks are executed. This method will return {@code false}
     * if all core threads have already been started.
     *
     * @return {@code true} if a thread was started
     */
    public boolean prestartCoreThread() {
        return workerCountOf(ctl.get()) < corePoolSize &&
            addWorker(null, true);
    }

ThreadPoolExecutor定义了prestartCoreThread,用于启动一个核心线程

prestartAllCoreThreads

java/util/concurrent/ThreadPoolExecutor.java

复制代码
    /**
     * Starts all core threads, causing them to idly wait for work. This
     * overrides the default policy of starting core threads only when
     * new tasks are executed.
     *
     * @return the number of threads started
     */
    public int prestartAllCoreThreads() {
        int n = 0;
        while (addWorker(null, true))
            ++n;
        return n;
    }

prestartAllCoreThreads用于启动所有的核心线程

小结

ThreadPoolExecutor提供了prestartCoreThread方法,用于启动一个核心线程,提供了prestartAllCoreThreads方法用于启动所有的核心线程。

相关推荐
m0_547486662 分钟前
《模式识别:使用MATLAB分析与实现》全套PPT课件
开发语言·matlab·模式识别
Tim_103 分钟前
【C++】009、extern关键字
java·开发语言
ShiXZ2135 分钟前
PDF-OCR文件识别篇(七):数据入库
java·pdf·json·ocr·springboot
rebibabo37 分钟前
Java基础(番外) | Kafka 入门:分区、副本与消费者组原理
java·分布式·kafka·学习笔记·副本·分区·异步日志
Flittly38 分钟前
【AgentScope Java新手村系列】(17)长期记忆系统
java·spring boot·spring
wei19862140 分钟前
.net添加web引用和添加服务引用有什么区别?
java·前端·.net
Full Stack Developme42 分钟前
正则表达式的使用教程
java·数据库·正则表达式
zhiSiBuYu05171 小时前
重排序(Rerank)提升检索准确率实战指南
开发语言·python·算法