ThreadPoolExecutor的七个参数详解
生活随笔
收集整理的這篇文章主要介紹了
ThreadPoolExecutor的七个参数详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
ThreadPoolExecutor的七個參數:
- corePoolSize 核心線程數
- MaxPS? 最大線程數
- keepAliveTime? 存活時間
- TimeUnit? 時間單位
- BlockingQueue? 任務隊列
- ThreadFactory? 線程工廠
- RejectStrategy? 拒絕策略
Abort??? 拋異常
Discard 悄悄扔掉
DiscardOld 扔掉最先的任務
CallerRuns 誰提交任務誰來執行
package com.zhangxueliang.demo.springbootdemo.JUC.c_026_01_ThreadPool;import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.Executors; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit;/*** @ProjectName springbootdemo_src* @ClassName T05_00_HelloThreadPool* @Desicription TODO* @Author Zhang Xueliang* @Date 2019/12/5 15:34* @Version 1.0**/ public class T05_00_HelloThreadPool{public class Task implements Runnable{int i;public Task(int i) {this.i = i;}@Overridepublic void run() {System.err.println(Thread.currentThread().getName()+" "+i);}} }class Test_T05_00_HelloThreadPool{public static void main(String[] args) {T05_00_HelloThreadPool t05_00_helloThreadPool = new T05_00_HelloThreadPool();ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 4, 60, TimeUnit.SECONDS,new ArrayBlockingQueue<Runnable>(4), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());try{for (int i = 0; i < 8; i++) {threadPoolExecutor.execute(t05_00_helloThreadPool.new Task(i));}System.err.println(threadPoolExecutor.getQueue());}finally {threadPoolExecutor.shutdown();}} }總結
以上是生活随笔為你收集整理的ThreadPoolExecutor的七个参数详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 通过ClassLoader加载硬盘上的图
- 下一篇: CompletableFuture并行异