聊聊线程池的预热

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

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方法用于启动所有的核心线程。

相关推荐
时寒的笔记几秒前
瑞数案例欧冶解读py和js文件最终版
开发语言·javascript·ecmascript
zmzb0103几秒前
Python课后习题训练记录Day123
开发语言·python
艾莉丝努力练剑2 分钟前
【Qt】事件
服务器·开发语言·网络·数据库·qt·tcp/ip·计算机网络
PersistJiao2 分钟前
python环境下免费、专业的中英翻译
开发语言·windows·python·机器翻译
rqtz4 分钟前
【C++】源码编译 Qt5.15.3|Ubuntu22.04 下 ROS 开发环境搭建
开发语言·c++·qt·ros
Jun6265 分钟前
QT(9)-Qjson移植
开发语言·qt
施棠海6 分钟前
自定义并可深度定制的数字滚动选择器完整源代码与相关注意事项
java·开发语言
z落落11 分钟前
C# 索引器 this[]
开发语言·c#
csdn_aspnet15 分钟前
C# List 移除某个属性值中最大的值
开发语言·c#·list