java線程池prestartCoreThread prestartAllCoreThreads的預(yù)熱源碼解讀
序
本文主要研究一下線程池的預(yù)熱
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,用于啟動(dòng)一個(gè)核心線程
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用于啟動(dòng)所有的核心線程
小結(jié)
ThreadPoolExecutor提供了prestartCoreThread方法,用于啟動(dòng)一個(gè)核心線程,提供了prestartAllCoreThreads方法用于啟動(dòng)所有的核心線程。
以上就是java線程池prestartCoreThread prestartAllCoreThreads的預(yù)熱源碼解讀的詳細(xì)內(nèi)容,更多關(guān)于java線程池預(yù)熱的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Java基于API接口爬取商品數(shù)據(jù)的示例代碼
Java作為一種流行的編程語(yǔ)言,可以用于編寫程序來(lái)調(diào)用這些API接口,從而獲取商品數(shù)據(jù),本文將介紹如何使用Java基于API接口爬取商品數(shù)據(jù),包括請(qǐng)求API、解析JSON數(shù)據(jù)、存儲(chǔ)數(shù)據(jù)等步驟,并提供相應(yīng)的代碼示例,感興趣的朋友跟隨小編一起看看吧2023-10-10
java使用apache.poi導(dǎo)出word文件的示例代碼
這篇文章主要介紹了java使用apache.poi導(dǎo)出word文件,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07
SpringBoot啟動(dòng)時(shí)如何通過(guò)啟動(dòng)參數(shù)指定logback的位置
這篇文章主要介紹了SpringBoot啟動(dòng)時(shí)如何通過(guò)啟動(dòng)參數(shù)指定logback的位置,在spring boot中,使用logback配置的方式常用的有兩種,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-07-07

