最經常使用構造方法爲:html
ThreadPoolExecutor(int corePoolSize,JAVA中IP和整數相互轉化
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,
java
RejectedExecutionHandler handler)緩存
JDK自帶的配置好的線程池: spa
// 固定工做線程數量的線程池
ExecutorService executorService1 = Executors.newFixedThreadPool(3);
// 一個可緩存的線程池
ExecutorService executorService2 = Executors.newCachedThreadPool();
// 單線程化的Executor
ExecutorService executorService3 = Executors.newSingleThreadExecutor();
// 支持定時的以及週期性的任務執行
ExecutorService executorService4 = Executors.newScheduledThreadPool(3);
這些預約義好的線程池服務也是基於ThreadPoolExecutor配置的,因此咱們應該從最基本的參數着手瞭解,以下:
參數詳細說明:集裝箱運費
[ 1 ]、corePoolSize: 線程池維護線程的最少數量
[ 2 ]、maximumPoolSize:線程池維護線程的最大數量
[ 3 ]、keepAliveTime: 線程池維護線程所容許的空閒時間
[ 4 ]、unit: 線程池維護線程所容許的空閒時間的單位,unit可選的參數爲java.util.concurrent.TimeUnit中的幾個靜態屬性:.net