开发者

java线程池prestartCoreThread prestartAllCoreThreads的预热源码解读

目录
  • prestartCoreThread
  • prestartAllCoreThreads
  • 小结

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

prestartCoreThread

Java/util/concurrent/ThreadPoolExecutor.java

/**
     * Starts a core thread, causing it to idly wait fojsr workwww.devze.com. 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 {@cphpode true} ifpython a androidthread 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方法用于启动所有的核心线程。

以上就是java线程池prestartCoreThread prestartAllCoreThreads的预热源码解读的详细内容,更多关于java线程池预热的资料请关注编程客栈(www.devze.com)其它相关文章!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新开发

开发排行榜