聊聊线程池的预热

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

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

相关推荐
hanbr1 小时前
C++ 初涉
开发语言·c++
Дерек的学习记录1 小时前
C++:入门基础(下)
开发语言·数据结构·c++·学习·算法·visualstudio
hzc09876543211 小时前
Spring Integration + MQTT
java·后端·spring
云小逸2 小时前
【nmap源码解析】Nmap 核心技术深度解析:从源码到实战
开发语言·网络·windows·nmap
前路不黑暗@2 小时前
Java项目:Java脚手架项目的公共模块的实现(二)
java·开发语言·spring boot·学习·spring cloud·maven·idea
人道领域2 小时前
Spring核心注解全解析
java·开发语言·spring boot
云深麋鹿2 小时前
标准库中的String类
开发语言·c++·容器
金牌归来发现妻女流落街头3 小时前
日志级别是摆设吗?
java·spring boot·日志
脱离语言3 小时前
Jeecg3.8.2 前端经验汇总
开发语言·前端·javascript
MOONICK3 小时前
C#基础入门
java·开发语言