当前位置:网站首页>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
边栏推荐
- CTF competition problem solution STM32 reverse introduction
- EditPlus--用法--快捷键/配置/背景色/字体大小
- Object detection based on OpenCV haarcascades
- [ODX studio edit PDX] - 0.2-how to compare two pdx/odx files of compare
- CTF竞赛题解之stm32逆向入门
- Docker镜像的缓存特性和Dockerfile
- How to choose a securities company? Is it safe to open an account on your mobile phone
- PaddleOCR教程
- The initial arrangement of particles in SPH (solved by two pictures)
- The difference between cout/cerr/clog
猜你喜欢

可观测|时序数据降采样在Prometheus实践复盘

蓝天NH55系列笔记本内存读写速度奇慢解决过程记录

Explanation of bitwise operators

QT drawing network topology diagram (connecting database, recursive function, infinite drawing, dragging nodes)

Blue sky nh55 series notebook memory reading and writing speed is extremely slow, solution process record

Redis:Redis消息的发布与订阅(了解)

Docker镜像的缓存特性和Dockerfile

Combien de temps faut - il pour obtenir un certificat PMP?

取得PMP证书需要多长时间?

壁仞科技研究院前沿技术文章精选
随机推荐
MP进阶操作: 时间操作, sql,querywapper,lambdaQueryWapper(条件构造器)快速筛选 枚举类
heatmap. JS picture hotspot heat map plug-in
[JS] - [dynamic planning] - Notes
企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)
qt绘制网络拓补图(连接数据库,递归函数,无限绘制,可拖动节点)
智力考验看成语猜古诗句微信小程序源码
【taichi】用最少的修改将太极的pbf2d(基于位置的流体模拟)改为pbf3d
ffmpeg快速剪辑
The solution to the lack of pcntl extension under MAMP, fatal error: call to undefined function pcntl_ signal()
P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
Recommended collection: build a cross cloud data warehouse environment, which is particularly dry!
LabVIEW中比较两个VI
Qualcomm WLAN framework learning (30) -- components supporting dual sta
Redis introduction complete tutorial: List explanation
PMP证书续证流程
【图论】拓扑排序
Async await used in map
PaddleOCR教程
为什么信息图会帮助你的SEO
Stm32 Reverse Introduction to CTF Competition Interpretation