聊聊线程池的预热

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

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

相关推荐
乐观勇敢坚强的老彭4 分钟前
GESP一级核心算法:循环与条件判断的结合
java·数据结构·算法
雪宫街道7 分钟前
SpringBoot 向 IOC 容器注册组件的两种姿势:@Configuration 与 @Import
java·spring boot·后端·spring
techdashen11 分钟前
Cargo 1.94 开发周期全解析
开发语言·后端·rust
charlie11451419120 分钟前
现代C++特性指南——constexpr 构造函数与字面类型
开发语言·c++
北城以北888823 分钟前
虚拟机安装JDK,Tomcat,部署项目
java·开发语言·tomcat
苏克贝塔25 分钟前
.NET开发之.net framework对比.net core
jvm
江华森26 分钟前
Python 3 实战教程:从零基础到项目实战
开发语言·python
Wonderful U30 分钟前
Python+Django实战|在线音乐分享平台:音乐上传、歌手专辑管理、在线播放、自定义歌单、收藏点赞、评论互动
开发语言·python·django
终将老去的穷苦程序员31 分钟前
基于Android Studio开发的安卓图书借阅管理系统
java·sqlite·android studio·android-studio
小糯米60139 分钟前
JavaScript表达式与运算符
开发语言·javascript·ecmascript