聊聊线程池的预热

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

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

相关推荐
翔云API2 分钟前
身份证识别接口的应用场景和作用
运维·服务器·开发语言·自动化·ocr
longlongqin3 分钟前
JVM 虚拟机的编译器、类加载过程、类加载器有哪些?
jvm
学java的小菜鸟啊15 分钟前
第五章 网络编程 TCP/UDP/Socket
java·开发语言·网络·数据结构·网络协议·tcp/ip·udp
zheeez19 分钟前
微服务注册中⼼2
java·微服务·nacos·架构
立黄昏粥可温19 分钟前
Python 从入门到实战22(类的定义、使用)
开发语言·python
PerfMan22 分钟前
基于eBPF的procstat软件追踪程序垃圾回收(GC)事件
linux·开发语言·gc·ebpf·垃圾回收·procstat
程序员-珍23 分钟前
SpringBoot v2.6.13 整合 swagger
java·spring boot·后端
徐*红30 分钟前
springboot使用minio(8.5.11)
java·spring boot·spring
聆听HJ30 分钟前
java 解析excel
java·开发语言·excel
溪午闻璐34 分钟前
C++ 文件操作
开发语言·c++