聊聊线程池的预热

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

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

相关推荐
神の愛30 分钟前
左连接查询数据 left join
java·服务器·前端
t***54436 分钟前
如何配置Orwell Dev-C++使用Clang
开发语言·c++
CoderCodingNo42 分钟前
【信奥业余科普】C++ 的奇妙之旅 | 13:为什么 0.1+0.2≠0.3?——解密“爆int”溢出与浮点数精度的底层原理
开发语言·c++
南境十里·墨染春水1 小时前
linux学习进展 线程同步——互斥锁
java·linux·学习
雨奔1 小时前
Kubernetes 联邦 Deployment 指南:跨集群统一管理 Pod
java·容器·kubernetes
杨凯凡1 小时前
【021】反射与注解:Spring 里背后的影子
java·后端·spring
lulu12165440781 小时前
Claude Code项目大了响应慢怎么办?Subagents、Agent Teams、Git Worktree、工作流编排四种方案深度解析
java·人工智能·python·ai编程
riNt PTIP1 小时前
SpringBoot创建动态定时任务的几种方式
java·spring boot·spring
老星*2 小时前
AI选股核心设计思路
java·ai·开源·软件开发
kongba0072 小时前
项目打包 Python Flask 项目发布与打包专家 提示词V1.0
开发语言·python·flask