聊聊线程池的预热

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

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

相关推荐
老秦包你会6 小时前
C++进阶------C++的类型转换
java·开发语言·c++
星辰烈龙6 小时前
黑马程序员JavaSE基础加强d2
java·开发语言
superman超哥6 小时前
仓颉性能瓶颈定位方法深度解析
c语言·开发语言·c++·python·仓颉
ps酷教程6 小时前
HttpObjectDecoder源码浅析
java·netty·httpaggregator
是苏浙6 小时前
零基础入门Java之认识String类
java·开发语言
leaves falling6 小时前
c语言-static和extern
c语言·开发语言
武汉唯众智创6 小时前
“物联网 Python 开发教程”课程教学解决方案
开发语言·python·物联网·物联网技术·物联网 python 开发·python 开发
悟空码字6 小时前
从零到一搭建SpringCloud微服务,一场代码世界的“分家”大戏
java·后端·spring cloud
时光Autistic6 小时前
【搭建教程】腾讯混元3D模型部署
开发语言·python·3d·github
于樱花森上飞舞6 小时前
【多线程】常见的锁策略与锁
java·开发语言·算法·java-ee