当前位置:网站首页>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
边栏推荐
- Servlet服务器端和客户端中文输出乱码问题
- 高通WLAN框架学习(30)-- 支持双STA的组件
- Qualcomm WLAN framework learning (30) -- components supporting dual sta
- 时间 (计算)总工具类 例子: 今年开始时间和今年结束时间等
- ECS settings SSH key login
- 位运算符讲解
- Financial markets, asset management and investment funds
- Qt加法计算器(简单案例)
- Observable time series data downsampling practice in Prometheus
- 香港珠宝大亨,22亿“抄底”佐丹奴
猜你喜欢

如何报考PMP项目管理认证考试?

MariaDB的Galera集群应用场景--数据库多主多活

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

Intelligence test to see idioms guess ancient poems wechat applet source code
![[Jianzhi offer] 6-10 questions](/img/73/5974068008bcdc9a70b3f5f57f1eb0.png)
[Jianzhi offer] 6-10 questions

为什么信息图会帮助你的SEO

实战模拟│JWT 登录认证
![[JS] - [sort related] - Notes](/img/b7/af467c7a169b73c3c4936072aef8b9.png)
[JS] - [sort related] - Notes

The initial trial is the cross device model upgrade version of Ruijie switch (taking rg-s2952g-e as an example)

PMP证书续证流程
随机推荐
MariaDB's Galera cluster application scenario -- multi master and multi active databases
微信小程序显示样式知识点总结
qt绘制网络拓补图(连接数据库,递归函数,无限绘制,可拖动节点)
认识ThreadPoolExecutor
HMS core machine learning service
uniapp 除了数字,其他输入无效
ScriptableObject
取得PMP證書需要多長時間?
Application of machine learning in housing price prediction
A complete tutorial for getting started with redis: redis usage scenarios
ICML 2022 || 3DLinker: 用于分子链接设计的E(3)等变变分自编码器
ECS settings SSH key login
ECCV 2022 | 腾讯优图提出DisCo:拯救小模型在自监督学习中的效果
【图论】拓扑排序
Examples of time (calculation) total tools: start time and end time of this year, etc
MariaDB的Galera集群-双主双活安装设置
Observable time series data downsampling practice in Prometheus
【taichi】用最少的修改将太极的pbf2d(基于位置的流体模拟)改为pbf3d
时间 (计算)总工具类 例子: 今年开始时间和今年结束时间等
Ffmpeg quick clip