聊聊线程池的预热

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

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

相关推荐
qq_281317477 分钟前
kubernetes(k8s)-pod生命周期
java·容器·kubernetes
IT界的奇葩15 分钟前
代码规范 spring-javaformat使用
java·spring·代码规范
披着羊皮不是狼23 分钟前
多用户跨学科交流系统(4)参数校验+分页搜索全流程的实现
java·spring boot
AI_567843 分钟前
接口测试“零基础通关“:Postman从入门到自动化测试实战指南
开发语言·lua
是Yu欸1 小时前
Rust 并发实战:从零构建一个内存安全的“番茄时钟”
开发语言·安全·rust
小池先生1 小时前
Gradle vs Maven 详细对比
java·maven
q***23921 小时前
基于SpringBoot和PostGIS的云南与缅甸的千里边境线实战
java·spring boot·spring
q***78781 小时前
Spring Boot的项目结构
java·spring boot·后端
应用市场2 小时前
Qt QTreeView深度解析:从原理到实战应用
开发语言·数据库·qt
q***96582 小时前
Spring Data JDBC 详解
java·数据库·spring