聊聊线程池的预热

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

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

相关推荐
superxxd21 分钟前
跨平台音频IO处理库libsoundio实践
开发语言·qt·音视频
没有bug.的程序员2 小时前
服务网格 Service Mesh:微服务通信的终极进化
java·分布式·微服务·云原生·service_mesh
_OP_CHEN2 小时前
C++基础:(十二)list类的基础使用
开发语言·数据结构·c++·stl·list类·list核心接口·list底层原理
南尘NCA86665 小时前
企业微信防封防投诉拦截系统:从痛点解决到技术实现
java·网络·企业微信
ONE_PUNCH_Ge5 小时前
Go 语言变量
开发语言
幼稚园的山代王5 小时前
go语言了解
开发语言·后端·golang
晚风残5 小时前
【C++ Primer】第六章:函数
开发语言·c++·算法·c++ primer
满天星83035775 小时前
【C++】AVL树的模拟实现
开发语言·c++·算法·stl
怪兽20145 小时前
SQL优化手段有哪些
java·数据库·面试