聊聊线程池的预热

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

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

相关推荐
SuperherRo3 小时前
JAVA攻防-Shiro专题&断点调试&有key利用链&URL&CC&CB&原生反序列化&加密逻辑
java·shiro·反序列化·有key·利用链·原生反序列化·加密逻辑
桦说编程4 小时前
简单方法实现子任务耗时统计
java·后端·监控
左直拳4 小时前
将c++程序部署到docker
开发语言·c++·docker
爱笑的眼睛114 小时前
超越可视化:降维算法组件的深度解析与工程实践
java·人工智能·python·ai
崇山峻岭之间4 小时前
Matlab学习记录31
开发语言·学习·matlab
盖世英雄酱581364 小时前
物品超领取损失1万事故复盘(一)
java·后端
CryptoRzz4 小时前
印度尼西亚(IDX)股票数据对接开发
java·后端·websocket·web3·区块链
独自破碎E4 小时前
JVM的内存区域是怎么划分的?
jvm
你怎么知道我是队长4 小时前
C语言---输入和输出
c语言·开发语言