聊聊线程池的预热

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

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

相关推荐
网小鱼的学习笔记1 分钟前
面试题1:==和equals的比较
java·jvm·面试
LegendNoTitle2 分钟前
Windows和Linux下Rust-init、Cargo下载慢的解决
开发语言·windows·rust
亓才孓7 分钟前
深浅拷贝--Java
java·开发语言·windows
潲爺11 分钟前
Java笔记总结
java·开发语言·笔记·学习
菜的不敢吱声13 分钟前
swift学习第一天
开发语言·学习·swift
培林将军16 分钟前
C语言指针
c语言·开发语言·算法
云栖梦泽18 分钟前
鸿蒙分布式应用全链路性能调优实战
开发语言·鸿蒙系统
jyd012421 分钟前
Spring Boot 文件上传大小限制问题:413 与 MaxUploadSizeExceededException 解决方案
java·spring boot·后端
yongui4783423 分钟前
基于卡尔曼滤波的电池荷电状态(SOC)估计的MATLAB实现
开发语言·算法·matlab
絔宝24 分钟前
Eclipse配置 Maven 国内镜像
java·eclipse·maven