聊聊线程池的预热

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

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

相关推荐
shark22222228 分钟前
Python 爬虫实战案例 - 获取社交平台事件热度并进行影响分析
开发语言·爬虫·python
宁波阿成8 分钟前
族谱管理系统架构分析与亮点总结
java·系统架构·vue·ruoyi-vue·族谱
姬成韶17 分钟前
BUUCTF--[RoarCTF 2019]Easy Java
java·网络安全
组合缺一17 分钟前
Solon AI Harness 首次发版
java·人工智能·ai·llm·agent·solon
551只玄猫19 分钟前
【数学建模 matlab 实验报告6】行遍性问题
开发语言·数学建模·matlab
AlunYegeer1 小时前
MyBatis 传参核心:#{ } 与 ${ } 区别详解(避坑+面试重点)
java·mybatis
乱蜂朝王1 小时前
使用 C# 和 ONNX Runtime 部署 PaDiM 异常检测模型
开发语言·c#
少许极端1 小时前
算法奇妙屋(四十)-贪心算法学习之路7
java·学习·算法·贪心算法
波诺波1 小时前
p1项目system_model.py代码
开发语言·python
危笑ioi1 小时前
helm部署skywalking链路追踪 java
java·开发语言·skywalking