聊聊线程池的预热

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

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

相关推荐
我是唐青枫1 分钟前
Java MyBatis 实战指南:XML 映射、动态 SQL 与数据访问层设计
java·mybatis
摇滚侠3 分钟前
Spring 零基础入门到进阶 面向切面 AOP 52-60
java·后端·spring
feifeigo1233 分钟前
马尔可夫决策过程(MDP)MATLAB 实现
开发语言·matlab
就改了12 分钟前
微服务接口性能优化:CompletableFuture 并行聚合实践
java·微服务·性能优化
攻城狮Soar12 分钟前
STL源码解析之list(1)
开发语言·c++
x***r15113 分钟前
Postman-win64-7.3.5-Setup安装配置教程(Windows 详细版)
开发语言·lua
林森lsjs13 分钟前
【日耕一题】4. 较为复杂情况下的求和
java·开发语言
Hui Baby15 分钟前
虚拟线程整理
java
2401_8697695917 分钟前
内容5 日期类实现
开发语言·c++
白露与泡影30 分钟前
2026秋招冲刺:1000道Java高频面试题(各大厂考点汇总)
java·开发语言·面试