当前位置:网站首页>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;
}
corePoolSize
Indicates 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 .
maximumPoolSize
Indicates that the thread pool increases when tasks increase , The maximum number of threads that can be created .
keepAliveTime
Indicates 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 .
unit
A unit of survival time
workQueue
Represents 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 .
threadFactory
Represents 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
边栏推荐
- MP进阶操作: 时间操作, sql,querywapper,lambdaQueryWapper(条件构造器)快速筛选 枚举类
- Financial markets, asset management and investment funds
- Galera cluster of MariaDB - dual active and dual active installation settings
- 推荐收藏:跨云数据仓库(data warehouse)环境搭建,这货特别干!
- 解决无法通过ssh服务远程连接虚拟机
- Advantages of Alibaba cloud international CDN
- 取得PMP證書需要多長時間?
- 为什么信息图会帮助你的SEO
- 可观测|时序数据降采样在Prometheus实践复盘
- Solution record of jamming when using CAD to move bricks in high configuration notebook
猜你喜欢
C语言快速解决反转链表
如何报考PMP项目管理认证考试?
CTF competition problem solution STM32 reverse introduction
The small program vant tab component solves the problem of too much text and incomplete display
The initial arrangement of particles in SPH (solved by two pictures)
P2181 对角线和P1030 [NOIP2001 普及组] 求先序排列
MIT-6.824-lab4B-2022(万字思路讲解-代码构建)
【剑指offer】1-5题
ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design
PS style JS webpage graffiti board plug-in
随机推荐
The caching feature of docker image and dockerfile
[binary tree] the maximum difference between a node and its ancestor
MariaDB的Galera集群应用场景--数据库多主多活
PS style JS webpage graffiti board plug-in
Redis:Redis消息的发布与订阅(了解)
Redis getting started complete tutorial: Key Management
Qualcomm WLAN framework learning (30) -- components supporting dual sta
Basic use and upgrade of Android native database
【ODX Studio编辑PDX】-0.3-如何删除/修改Variant变体中继承的(Inherited)元素
Qt加法计算器(简单案例)
mamp下缺少pcntl扩展的解决办法,Fatal error: Call to undefined function pcntl_signal()
Summary of wechat applet display style knowledge points
ffmpeg快速剪辑
P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
【二叉树】节点与其祖先之间的最大差值
MySQL数据库备份与恢复--mysqldump命令
The difference between cout/cerr/clog
Examples of time (calculation) total tools: start time and end time of this year, etc
微信公众号解决从自定义菜单进入的缓存问题
机器学习在房屋价格预测上的应用