創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!
這篇文章將為大家詳細(xì)講解有關(guān)java 中ThreadPoolExecutor的原理是什么,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
java 中ThreadPoolExecutor原理分析
線程池簡介
Java線程池是開發(fā)中常用的工具,當(dāng)我們有異步、并行的任務(wù)要處理時,經(jīng)常會用到線程池,或者在實(shí)現(xiàn)一個服務(wù)器時,也需要使用線程池來接收連接處理請求。
線程池使用
JDK中提供的線程池實(shí)現(xiàn)位于java.util.concurrent.ThreadPoolExecutor。在使用時,通常使用ExecutorService接口,它提供了submit,invokeAll,shutdown等通用的方法。
在線程池配置方面,Executors類中提供了一些靜態(tài)方法能夠提供一些常用場景的線程池,如newFixedThreadPool,newCachedThreadPool,newSingleThreadExecutor等,這些方法最終都是調(diào)用到了ThreadPoolExecutor的構(gòu)造函數(shù)。
ThreadPoolExecutor的包含所有參數(shù)的構(gòu)造函數(shù)是
/** * @param corePoolSize the number of threads to keep in the pool, even * if they are idle, unless {@code allowCoreThreadTimeOut} is set * @param maximumPoolSize the maximum number of threads to allow in the * pool * @param keepAliveTime when the number of threads is greater than * the core, this is the maximum time that excess idle threads * will wait for new tasks before terminating. * @param unit the time unit for the {@code keepAliveTime} argument * @param workQueue the queue to use for holding tasks before they are * executed. This queue will hold only the {@code Runnable} * tasks submitted by the {@code execute} method. * @param threadFactory the factory to use when the executor * creates a new thread * @param handler the handler to use when execution is blocked * because the thread bounds and queue capacities are reached public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) { if (corePoolSize < 0 || maximumPoolSize <= 0 || maximumPoolSize < corePoolSize || keepAliveTime < 0) throw new IllegalArgumentException(); if (workQueue == null || threadFactory == null || handler == null) throw new NullPointerException(); this.corePoolSize = corePoolSize; this.maximumPoolSize = maximumPoolSize; this.workQueue = workQueue; this.keepAliveTime = unit.toNanos(keepAliveTime); this.threadFactory = threadFactory; this.handler = handler; }
網(wǎng)頁標(biāo)題:java中ThreadPoolExecutor的原理是什么-創(chuàng)新互聯(lián)
URL分享:http://vcdvsql.cn/article20/ddjoco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、App設(shè)計、網(wǎng)站改版、全網(wǎng)營銷推廣、服務(wù)器托管、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容