聊聊线程池的预热

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

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

相关推荐
qq_40170041几秒前
嵌入式C语言设计模式
c语言·开发语言·设计模式
minh_coo1 分钟前
Spring单元测试之反射利器:ReflectionTestUtils
java·后端·spring·单元测试·intellij-idea
二十画~书生4 分钟前
【2025年全国大学生电子设计大赛-国二】超声信标定位系统 (J 题)
开发语言·javascript·经验分享·ecmascript·硬件工程
野生技术架构师6 分钟前
Spring Boot + JPackage:构建独立安装包!
java·spring boot·后端
童话的守望者7 分钟前
dc9靶场通关
java·开发语言
弹简特7 分钟前
【JavaEE11-后端部分】SpringMVC06-综合案例2-从用户登录看前后端交互:接口文档与HTTP通信详解
java·spring boot·spring·http·java-ee·tomcat
大黄说说10 分钟前
解锁 .NET 性能极限:深入解析 Span 与零拷贝内存艺术
java·数据结构·算法
zh_xuan10 分钟前
kotlin 作用域函数run
开发语言·kotlin
知识即是力量ol12 分钟前
深入理解 Snowflake 雪花算法:原理、本质、趋势递增问题与分布式顺序困境全解析
java·分布式·算法·雪花算法·snowflake·全局唯一id·分布式id生成器
君爱学习13 分钟前
G1垃圾回收器启动时 CPU 飙升的原因分析
java