聊聊线程池的预热

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

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

相关推荐
Once_day3 分钟前
C++之《程序员自我修养》读书总结(1)
c语言·开发语言·c++·程序员自我修养
若鱼19196 分钟前
SpringBoot4.0新特性-Observability让生产环境更易于观测
java·spring
觉醒大王15 分钟前
强女思维:着急,是贪欲外显的相。
java·论文阅读·笔记·深度学习·学习·自然语言处理·学习方法
喜欢喝果茶.22 分钟前
QOverload<参数列表>::of(&函数名)信号槽
开发语言·qt
亓才孓23 分钟前
[Class类的应用]反射的理解
开发语言·python
努力学编程呀(๑•ี_เ•ี๑)23 分钟前
【在 IntelliJ IDEA 中切换项目 JDK 版本】
java·开发语言·intellij-idea
码农小卡拉32 分钟前
深入解析Spring Boot文件加载顺序与加载方式
java·数据库·spring boot
向上的车轮39 分钟前
为什么.NET(C#)转 Java 开发时常常在“吐槽”Java:checked exception
java·c#·.net
Dragon Wu41 分钟前
Spring Security Oauth2.1 授权码模式实现前后端分离的方案
java·spring boot·后端·spring cloud·springboot·springcloud
island131444 分钟前
CANN GE(图引擎)深度解析:计算图优化管线、内存静态规划与异构任务的 Stream 调度机制
开发语言·人工智能·深度学习·神经网络