創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!
這篇文章給大家介紹深入淺析Java中ThreadPoolExecutor的參數(shù),內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
Java ThreadPoolExecutor的參數(shù)深入理解
一、使用Executors創(chuàng)建線程池
之前創(chuàng)建線程的時候都是用的Executors的newFixedThreadPool(),newSingleThreadExecutor(),newCachedThreadPool()這三個方法。當(dāng)然Executors也是用不同的參數(shù)去new ThreadPoolExecutor
1. newFixedThreadPool()
創(chuàng)建線程數(shù)固定大小的線程池。 由于使用了LinkedBlockingQueue所以maximumPoolSize 沒用,當(dāng)corePoolSize滿了之后就加入到LinkedBlockingQueue隊列中。每當(dāng)某個線程執(zhí)行完成之后就從LinkedBlockingQueue隊列中取一個。所以這個是創(chuàng)建固定大小的線程池。
public static ExecutorService newFixedThreadPool(int nThreads) { return new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); } public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) { this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, Executors.defaultThreadFactory(), defaultHandler); }
當(dāng)前文章:深入淺析Java中ThreadPoolExecutor的參數(shù)-創(chuàng)新互聯(lián)
本文來源:http://www.rwnh.cn/article2/jogic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、網(wǎng)站設(shè)計公司、品牌網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、小程序開發(fā)、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容