美文网首页
聊聊线程池的预热

聊聊线程池的预热

作者: go4it | 来源:发表于2023-10-22 20:59 被阅读0次

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

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

相关文章

  • 聊聊线程池

    线程池:指管理一组同构工作线程的资源池。线程池与工作队列(Work Queue)密切相关,其中在工作队列中保存了所...

  • 聊聊Java线程池原理

    线程池是很常用的并发框架,几乎所有需要异步和并发处理任务的程序都可用到线程池。使用线程池的好处如下: 降低资源消耗...

  • java----线程池

    什么是线程池 为什么要使用线程池 线程池的处理逻辑 如何使用线程池 如何合理配置线程池的大小 结语 什么是线程池 ...

  • java线程池

    线程VS线程池 普通线程使用 创建线程池 执行任务 执行完毕,释放线程对象 线程池 创建线程池 拿线程池线程去执行...

  • 漫画:聊聊线程池中,线程的增长/回收策略

    一、序 我们今天就来借这个问题,聊聊线程池中维护的线程,它增长和回收的策略是什么样的? 二、线程池的策略 2.1 ...

  • 简体字、冯|聊聊 fork-join框架

    title: 2018-8-3 聊聊 fork-join框架tags: java,并发,线程池grammar_cj...

  • Spring Boot之ThreadPoolTaskExecut

    初始化线程池 corePoolSize 线程池维护线程的最少数量keepAliveSeconds 线程池维护线程...

  • 线程池

    1.线程池简介 1.1 线程池的概念 线程池就是首先创建一些线程,它们的集合称为线程池。使用线程池可以很好地提高性...

  • java 线程池使用和详解

    线程池的使用 构造方法 corePoolSize:线程池维护线程的最少数量 maximumPoolSize:线程池...

  • ThreadPoolExecutor线程池原理以及源码分析

    线程池流程: 线程池核心类:ThreadPoolExecutor:普通的线程池ScheduledThreadPoo...

网友评论

      本文标题:聊聊线程池的预热

      本文链接:https://www.haomeiwen.com/subject/zxddidtx.html