聊聊线程池的预热

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

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

相关推荐
独自破碎E1 分钟前
已经 Push 到远程的提交,如何修改 Commit 信息?
开发语言·github
缘空如是3 分钟前
基础工具之jsoup工具
java·jsoup·html解析
毕设源码-郭学长5 分钟前
【开题答辩全过程】以 基于Nodejs的网上书店 为例,包含答辩的问题和答案
java·eclipse
you-_ling13 分钟前
Linux软件编程:Shell命令
java·linux·服务器
数智工坊15 分钟前
【数据结构-栈、队列、数组】3.3栈在括号匹配-表达式求值上
java·开发语言·数据结构
凌康ACG15 分钟前
Warm-Flow国产工作流引擎入门
java·工作流引擎·flowable·warm-flow
lsx20240616 分钟前
Bootstrap 插件概览
开发语言
毕设源码-钟学长17 分钟前
【开题答辩全过程】以 基于PHP的动漫社区的设计与实现为例,包含答辩的问题和答案
开发语言·php
知我心·20 分钟前
Java 正则表达式知识点总结
java
indexsunny20 分钟前
互联网大厂Java面试实战:微服务与Spring生态技术解析
java·spring boot·redis·kafka·mybatis·hibernate·microservices