聊聊线程池的预热

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

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

相关推荐
无心水2 分钟前
【神经风格迁移:全链路压测】33、全链路监控与性能优化最佳实践:Java+Python+AI系统稳定性保障的终极武器
java·python·性能优化
萧曵 丶11 分钟前
Synchronized 详解及 JDK 版本优化
java·多线程·synchronized
夏幻灵26 分钟前
JAVA基础:基本数据类型和引用数据类型
java·开发语言
weixin1997010801632 分钟前
闲鱼 item_get - 商品详情接口对接全攻略:从入门到精通
java·后端·spring
cike_y1 小时前
Spring-Bean的作用域&Bean的自动装配
java·开发语言·数据库·spring
qq_12498707531 小时前
基于深度学习的蘑菇种类识别系统的设计与实现(源码+论文+部署+安装)
java·大数据·人工智能·深度学习·cnn·cnn算法
十八度的天空1 小时前
第01节 Python的基础语法
开发语言·python
谈笑也风生1 小时前
经典算法题型之排序算法(三)
java·算法·排序算法
yue0082 小时前
C# 字符串倒序
开发语言·c#
自己的九又四分之三站台2 小时前
导入数据到OG GraphQL以及创建graph
java·后端·graphql