聊聊线程池的预热

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

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

相关推荐
hello 早上好13 小时前
07_JVM 双亲委派机制
开发语言·jvm
前端程序猿i13 小时前
第 8 篇:Markdown 渲染引擎 —— 从流式解析到安全输出
开发语言·前端·javascript·vue.js·安全
Java小卷13 小时前
KIE Drools 10.x 规则引擎快速入门
java·后端
kronos.荒13 小时前
滑动窗口:寻找字符串中的字母异位词
开发语言·python
fengsen521131413 小时前
Windows操作系统部署Tomcat详细讲解
java·windows·tomcat
竟未曾年少轻狂13 小时前
Spring Boot 项目集成 Redis
java·spring boot·redis·缓存·消息队列·wpf·redis集群
_codemonster14 小时前
java web修改了文件和新建了文件需要注意的问题
java·开发语言·前端
Java天梯之路14 小时前
Spring Boot 钩子全集实战(九):`@PostConstruct` 详解
java·spring boot·后端
松涛和鸣14 小时前
75、 IMX6ULL LM75温度传感器I2C驱动开发
java·linux·数据库·驱动开发·python
甄心爱学习14 小时前
【python】list的底层实现
开发语言·python