当前位置:网站首页>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
边栏推荐
- Excel shortcut keys - always add
- Mysql database backup and recovery -- mysqldump command
- VIM editor knowledge summary
- Qualcomm WLAN framework learning (30) -- components supporting dual sta
- debug和release的区别
- Header file duplicate definition problem solving "c1014 error“
- HMS core unified scanning service
- 壁仞科技研究院前沿技术文章精选
- [ODX studio edit PDX] - 0.2-how to compare two pdx/odx files of compare
- QT personal learning summary
猜你喜欢
Qualcomm WLAN framework learning (30) -- components supporting dual sta
SPH中的粒子初始排列问题(两张图解决)
[Jianzhi offer] 6-10 questions
取得PMP证书需要多长时间?
【剑指offer】1-5题
PS style JS webpage graffiti board plug-in
CTF競賽題解之stm32逆向入門
LabVIEW中比较两个VI
Selected cutting-edge technical articles of Bi Ren Academy of science and technology
Why does infographic help your SEO
随机推荐
[ODX studio edit PDX] - 0.2-how to compare two pdx/odx files of compare
[sword finger offer] questions 1-5
Redis getting started complete tutorial: Key Management
HMS core unified scanning service
PaddleOCR教程
【ODX Studio編輯PDX】-0.2-如何對比Compare兩個PDX/ODX文件
Notepad++ -- editing skills
Qt加法计算器(简单案例)
Question brushing guide public
List related knowledge points to be sorted out
ETCD数据库源码分析——处理Entry记录简要流程
The caching feature of docker image and dockerfile
Summary of wechat applet display style knowledge points
Docker镜像的缓存特性和Dockerfile
Intelligence test to see idioms guess ancient poems wechat applet source code
ECCV 2022 | 腾讯优图提出DisCo:拯救小模型在自监督学习中的效果
一次edu证书站的挖掘
How to apply for PMP project management certification examination?
高通WLAN框架学习(30)-- 支持双STA的组件
实战模拟│JWT 登录认证