java線程池prestartCoreThread prestartAllCoreThreads的預熱源碼解讀
更新時間:2023年10月24日 09:30:08 作者:codecraft
這篇文章主要介紹了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線程池預熱的資料請關注腳本之家其它相關文章!
相關文章
idea啟動多個SpringBoot服務實例的最優(yōu)解決方法
啟動SpringBoot項目其實就是啟動Tomcat等服務容器,只要這個端口不同就能啟動多個服務實例了,本文主要介紹了idea啟動多個SpringBoot服務實例的最優(yōu)解決方法,感興趣的可以了解一下2024-05-05

