java线程池prestartCoreThread prestartAllCoreThreads的预热源码解读
序
本文主要研究一下线程池的预热
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方法用于启动所有的核心线程。
以上就是java线程池prestartCoreThread prestartAllCoreThreads的预热源码解读的详细内容,更多关于java线程池预热的资料请关注脚本之家其它相关文章!
相关文章
IntelliJ IDEA使用教程从入门到上瘾(2019图文版)
这篇文章主要介绍了IntelliJ IDEA使用教程从入门到上瘾(2019图文版),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-12-12@RequestMapping 如何使用@PathVariable 从URI中获取参数
这篇文章主要介绍了@RequestMapping 如何使用@PathVariable 从URI中获取参数的操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2021-08-08JavaSE API实现生成随机数的2种方法(Random类和Math类的Random方法)
本文主要介绍了JavaSE API实现生成随机数的2种方法,主要包括Random类和Math类的random方法都可以用来生成随机数,具有一定的参考价值,感兴趣的可以了解一下2023-10-10
最新评论