当前位置:网站首页>Meet ThreadPoolExecutor
Meet ThreadPoolExecutor
2022-07-04 23:23:00 【InfoQ】
Creation of thread pool
- FixedThreadPool: The allowed request queue length is Integer.MAX_VALUE, A large number of requests may pile up , Which leads to OOM.
- SingleThreadPool: and FixedThreadPool Will face the same problem
- CachedThreadPool : The number of threads allowed to be created is Integer.MAX_VALUE, A large number of threads may be created , Which leads to OOM.
- ScheduledThreadPool: and CachedThreadPool Will face the same problem
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.acc = System.getSecurityManager() == null ?
null :
AccessController.getContext();
this.corePoolSize = corePoolSize;
this.maximumPoolSize = maximumPoolSize;
this.workQueue = workQueue;
this.keepAliveTime = unit.toNanos(keepAliveTime);
this.threadFactory = threadFactory;
this.handler = handler;
}
corePoolSizeIndicates the number of core threads in the thread pool . If set to 0, The thread pool will be destroyed when there are no tasks ; If it is greater than 0, Even if there are no tasks, the number of threads in the thread pool will be guaranteed to be equal to this value .
maximumPoolSizeIndicates that the thread pool increases when tasks increase , The maximum number of threads that can be created .
keepAliveTimeIndicates the lifetime of the thread , When the thread pool is idle and exceeds this time , The extra threads will be destroyed , Until the number of threads in the thread pool is equal to corePoolSize until , If maximumPoolSize be equal to corePoolSize, Then the thread pool will not destroy any threads when it is idle .
unitA unit of survival time
workQueueRepresents the task queue executed by the thread pool , When all threads in the thread pool are processing tasks , If a new task comes, it will be cached in this task queue and queued for execution .
threadFactoryRepresents the creation factory of the thread
Submit thread tasks
- submit()
- execute()
Task rejection policy
- AbortPolicy, Termination strategy , The thread pool throws an exception and terminates execution , It is the default rejection policy ;
- CallerRunsPolicy, Give the task to the current thread to execute ;
- DiscardPolicy, Ignore this task ( The latest mission );
- DiscardOldestPolicy, Ignore the earliest tasks ( The first task to join the queue ).
- Custom reject policy
边栏推荐
- ECCV 2022 | Tencent Youtu proposed disco: the effect of saving small models in self supervised learning
- [JS] - [dynamic planning] - Notes
- 香港珠宝大亨,22亿“抄底”佐丹奴
- 【js】-【动态规划】-笔记
- cout/cerr/clog的区别
- ffmpeg快速剪辑
- [ODX studio edit PDX] -0.3- how to delete / modify inherited elements in variant variants
- [Jianzhi offer] 6-10 questions
- S32 Design Studio for ARM 2.2 快速入门
- [crawler] jsonpath for data extraction
猜你喜欢

壁仞科技研究院前沿技术文章精选

JS card style countdown days

How to apply for PMP project management certification examination?

【kotlin】第三天

The difference between cout/cerr/clog

Etcd database source code analysis - brief process of processing entry records

OSEK标准ISO_17356汇总介绍

初试为锐捷交换机跨设备型号升级版本(以RG-S2952G-E为例)

法国学者:最优传输理论下对抗攻击可解释性探讨

A mining of edu certificate station
随机推荐
QT drawing network topology diagram (connecting database, recursive function, infinite drawing, dragging nodes)
HMS core unified scanning service
Object detection based on OpenCV haarcascades
Redis getting started complete tutorial: Key Management
刷题指南-public
French scholars: the explicability of counter attack under optimal transmission theory
C language to quickly solve the reverse linked list
ICML 2022 || 3DLinker: 用于分子链接设计的E(3)等变变分自编码器
Pict generate orthogonal test cases tutorial
MIT-6.824-lab4B-2022(万字思路讲解-代码构建)
ScriptableObject
Mysql database backup and recovery -- mysqldump command
PaddleOCR教程
OSEK标准ISO_17356汇总介绍
头文件重复定义问题解决“C1014错误“
股票账户佣金怎么调低,炒股佣金怎么调低网上开户安全吗
字体设计符号组合多功能微信小程序源码
华泰证券低佣金的开户链接安全吗?
Basic use and upgrade of Android native database
【kotlin】第三天