欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java線程池prestartCoreThread prestartAllCoreThreads的預(yù)熱源碼解讀

 更新時(shí)間:2023年10月24日 09:30:08   作者:codecraft  
這篇文章主要介紹了java線程池prestartCoreThread prestartAllCoreThreads的預(yù)熱源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

本文主要研究一下線程池的預(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)文章

最新評(píng)論