聊聊线程池的预热

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

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

相关推荐
朝新_8 分钟前
【EE初阶】JVM
java·开发语言·网络·jvm·笔记·算法·javaee
不见长安在9 分钟前
Jvm资料整理
jvm·1024程序员节
如果丶可以坑13 分钟前
maven无法获取依赖问题
java·maven·1024程序员节
Arlene16 分钟前
JVM 的垃圾回收机制
jvm
Reggie_L25 分钟前
RabbitMQ -- 保障消息可靠性
开发语言·后端·ruby
blammmp34 分钟前
RabbitMQ :概述,Web界面介绍,快速上手,工作模式
java·分布式·rabbitmq
何中应35 分钟前
如何截取PDF内容为图片
java·开发语言·后端·pdf
边洛洛1 小时前
next.js项目部署流程
开发语言·前端·javascript