聊聊线程池的预热

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

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

相关推荐
another heaven1 天前
【Qt VS2022调试时无法查看QString等Qt变量信息】解决方法
开发语言·qt
A黄俊辉A1 天前
axios+ts封装
开发语言·前端·javascript
异常驯兽师1 天前
Spring 中处理 HTTP 请求参数注解全解析
java·spring·http
连合机器人1 天前
晨曦中的守望者:当科技为景区赋予温度
java·前端·科技
杨福瑞1 天前
C语⾔内存函数
c语言·开发语言
AD钙奶-lalala1 天前
idea新建的项目new 没有java class选项
java·ide·intellij-idea
eqwaak01 天前
科技信息差(9.12)
开发语言·python·科技·量子计算
axban1 天前
QT M/V架构开发实战:QStringListModel介绍
开发语言·数据库·qt
刘媚-海外1 天前
Go语言开发AI应用
开发语言·人工智能·golang·go
sheji34161 天前
【开题答辩全过程】以 12306候补购票服务系统为例,包含答辩的问题和答案
java·eclipse