聊聊线程池的预热

序

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

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

相关推荐
程序员老陆20 分钟前
C++ 未定义行为全景:对象模型、优化边界与工程防御
开发语言·c++·程序设计
嵌入式er34 分钟前
影石系统组 一二面OC面经
java·开发语言
徐小黑ACG35 分钟前
Golang 基础06 接口interface
开发语言·后端·golang
春涧草茶35 分钟前
慢就是快12-12手动抛出异常
java·linux·前端
半杯咖啡半行码36 分钟前
Qt 开发基础:版本演进、常用工具与多平台安装
开发语言·qt
下页、再停留1 小时前
【C#桌面客户端系列学习-8】批量导出数据为csv格式
开发语言·c#·visual studio
菜鸟~noob2331 小时前
【电子战】 第26篇:大气衰减——氧气与水汽吸收【含matlab代码】
开发语言·matlab
菜鸟~noob2331 小时前
【电子战】第25篇:自由空间、双射线与菲涅尔区【含matlab代码】
开发语言·算法·matlab
企业数字化笔记1 小时前
AI工具参数很多怎么办?预设、表单校验、危险参数与配置审计
java·spring boot·python·音视频