新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
java線程池對象ThreadPoolExecutor的深入講解-創(chuàng)新互聯(lián)
使用線程池的好處
1、降低資源消耗
可以重復(fù)利用已創(chuàng)建的線程降低線程創(chuàng)建和銷毀造成的消耗。
2、提高響應(yīng)速度
當(dāng)任務(wù)到達(dá)時(shí),任務(wù)可以不需要等到線程創(chuàng)建就能立即執(zhí)行。
3、提高線程的可管理性
線程是稀缺資源,如果無限制地創(chuàng)建,不僅會消耗系統(tǒng)資源,還會降低系統(tǒng)的穩(wěn)定性,使用線程池可以進(jìn)行統(tǒng)一分配、調(diào)優(yōu)和監(jiān)控
ThreadPoolExecutor 介紹:
java 提供的線程池類;
ThreadPoolExecutor 作用:
兩個(gè)作用:
1,用于分離執(zhí)行任務(wù)和當(dāng)前線程;
2,主要設(shè)計(jì)初衷:重復(fù)利用Thread 對象;
ThreadPoolExecutor 使用:
實(shí)例化:
public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueueworkQueue) { this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, Executors.defaultThreadFactory(), defaultHandler); }
當(dāng)前文章:java線程池對象ThreadPoolExecutor的深入講解-創(chuàng)新互聯(lián)
轉(zhuǎn)載來于:http://fisionsoft.com.cn/article/hsigo.html