聊聊线程池的预热

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

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

相关推荐
好好沉淀11 分钟前
Apache 工具包(commons-io commons-lang3 )保姆介绍
java·ide
毕设源码-邱学长15 分钟前
【开题答辩全过程】以 服装购物平台为例,包含答辩的问题和答案
java·eclipse
无敌最俊朗@20 分钟前
C++后端总览
开发语言
多喝开水少熬夜26 分钟前
堆相关算法题基础-java实现
java·开发语言·算法
richxu2025100127 分钟前
Java开发环境搭建之 10.使用IDEA创建和管理Mysql数据库
java·ide·intellij-idea
7澄133 分钟前
Java 集合框架:List 体系与实现类深度解析
java·开发语言·vector·intellij-idea·集合·arraylist·linkedlist
行思理33 分钟前
IntelliJIdea 工具新手操作技巧
java·spring·intellijidea
mit6.8241 小时前
一些C++的学习资料备忘
开发语言·c++
Adellle1 小时前
Java中同步和异步的区别,以及阻塞和非阻塞的区别
java·开发语言
qq_12498707531 小时前
基于springboot+vue的物流管理系统的设计与实现(源码+论文+部署+安装)
java·spring boot·后端·毕业设计