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线程池预热的资料请关注脚本之家其它相关文章!
相关文章
Spring-基于Spring使用自定义注解及Aspect实现数据库切换操作
这篇文章主要介绍了Spring-基于Spring使用自定义注解及Aspect实现数据库切换操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2020-09-09
AsyncHttpClient exception异常源码流程解析
这篇文章主要为大家介绍了AsyncHttpClient的exception源码流程解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-12-12
用html css javascript打造自己的RIA图文教程
用html&css&javascript打造自己的RIA之一,包括了配置等2009-07-07
SpringBoot前后端分离项目之打包、部署到服务器详细图文流程
作为后台开发,项目打包部署是经常性的操作,下面这篇文章主要给大家介绍了关于SpringBoot前后端分离项目之打包、部署到服务器的相关资料,文中通过代码示例介绍的非常详细,需要的朋友可以参考下2023-12-12


最新评论