当前位置:网站首页>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
边栏推荐
- 刷题指南-public
- CTF competition problem solution STM32 reverse introduction
- MariaDB的Galera集群-双主双活安装设置
- QT personal learning summary
- Selected cutting-edge technical articles of Bi Ren Academy of science and technology
- A mining of edu certificate station
- Explanation of bitwise operators
- Async await used in map
- Excel 快捷键-随时补充
- Editplus-- usage -- shortcut key / configuration / background color / font size
猜你喜欢
Phpcms paid reading function Alipay payment
Tweenmax emoticon button JS special effect
JS card style countdown days
qt绘制网络拓补图(连接数据库,递归函数,无限绘制,可拖动节点)
Excel 快捷键-随时补充
OSEK标准ISO_17356汇总介绍
PS style JS webpage graffiti board plug-in
[binary tree] the maximum difference between a node and its ancestor
一次edu证书站的挖掘
EditPlus--用法--快捷键/配置/背景色/字体大小
随机推荐
EditPlus--用法--快捷键/配置/背景色/字体大小
MP进阶操作: 时间操作, sql,querywapper,lambdaQueryWapper(条件构造器)快速筛选 枚举类
OSEK标准ISO_17356汇总介绍
【kotlin】第三天
解决无法通过ssh服务远程连接虚拟机
智力考验看成语猜古诗句微信小程序源码
壁仞科技研究院前沿技术文章精选
Phpcms paid reading function Alipay payment
【js】-【排序-相关】-笔记
Selected cutting-edge technical articles of Bi Ren Academy of science and technology
A complete tutorial for getting started with redis: redis usage scenarios
Etcd database source code analysis - brief process of processing entry records
Advantages of Alibaba cloud international CDN
MariaDB's Galera cluster application scenario -- multi master and multi active databases
Compare two vis in LabVIEW
Notepad++--编辑的技巧
Async await used in map
Application of machine learning in housing price prediction
Explanation of bitwise operators
French scholars: the explicability of counter attack under optimal transmission theory