当前位置:网站首页>Thread pool parameters and reasonable settings
Thread pool parameters and reasonable settings
2022-07-05 19:43:00 【androidstarjack】
Click on the top “ Terminal R & D department ”
Set to “ Star standard ”, Master more database knowledge with you One 、 Thread pool 7 Big core parameters
1. corePoolSize
Number of core threads core threads will always survive , In time, there is no task to perform , When the number of threads is less than the number of core threads , Even if there are threads free , Thread pool will also give priority to creating new thread processing when set allowCoreThreadTimeout=true( Default false) when , The core thread will time out to close
2. maximumPoolSize Maximum number of threads
When the idle thread time reaches keepAliveTime, The thread will shut down , Until the quantity equals corePoolSize
3. keepAliveTime free time
4. unit Time unit
It exceeds the lifetime unit of the core thread , As second 、 Ms etc. .
5. workQueue Blocking queues
LinkedBlockingQueue: Unbounded queue , Capacity Integer.MAX_VALUE,(FixedThreadPool and SingleThreadExecutor The number of threads in the thread pool is fixed , It's used LinkedBlockingQueue)
SynchronousQueue: Directly submitted task queue (CachedThreadPool Is the maximum number of threads Integer.MAX_VALUE, It's using SynchronousQueue)
ArrayBlockingQueue: Specify the queue size (corePoolSize > queue >maximumPoolSize )
6. threadFactory Thread factory
You can customize the creation of Thread objects , For example, set the thread name 、 Whether it is a guardian thread, etc .
7. handler Refusal strategy
AbortPolicy: Termination strategy . The maximum load is exceeded 、 When performing a reject task , Will directly throw a type of RejectedExecutionException Of RuntimeException abnormal
CallerRunsPolicy: The caller executes the policy . Over load , When executing policy , The caller thread performs the task .
DiscardOldestPolicy: Discard the earliest task strategy . Over load , Discard the oldest task in the queue . If the route pool is closed , Give up .
DiscardPolicy: Discard strategy . Over load , Discarding the task .
Realization RejectedExecutionHandler Interface , Custom policy
Two 、 Reasonable setting of thread pool parameters
Ø tasks, The maximum number of tasks that the program needs to process per second
Ø tasktime, The time required for a single thread to process a task
Ø responsetime, The system allows the maximum response time for tasks
corePoolSize
Each task requires tasktime Second processing , Then each thread can process 1/tasktime A mission . The system has... Per second tasks A task needs to be handled , The number of threads required is :tasks/(1/tasktime). namely tasks*tasktime Number of threads . The specific figures should be based on 8020 principle , namely 80% In this case, the number of system tasks per second .
queueCapacity: The length of the task queue
The length of the task queue depends on the number of core threads , And the requirements of the system for task response time . The queue length can be set to (corePoolSize/tasktime)responsetime
maxPoolSize: Maximum number of threads
When the system load reaches the maximum , The number of core threads has failed to complete all tasks on time , In this case, you need to add threads . Per second 200 A task requires 20 Threads , So when every second reaches 1000 A task , You need to (1000-queueCapacity)*(20/200).
keepAliveTime
keepAliveTiime The set value can be set according to the peak duration of the task .
The above calculation of the number of threads does not consider CPU The situation of . If combined CPU The situation of , such as , When the number of threads reaches 50 when ,CPU achieve 100%, Will maxPoolSize Set to 60 It's not appropriate , At this time, if the system load is maintained at every second for a long time 1000 A mission , Then it exceeds the processing capacity of the process pool , Try to reduce the processing time of each task (tasktime).
Write it at the end
You can leave a message below to discuss what you don't understand , You can also ask me by private message. I will reply after seeing it . Finally, if the article is helpful to you, please remember to give me a like , Pay attention and don't get lost
@ Terminal R & D department
Fresh dry goods are shared every day !
reply 【idea Activate 】 You can get idea How to activate
reply 【Java】 obtain java Relevant video tutorials and materials
reply 【SpringCloud】 obtain SpringCloud Many relevant learning materials
reply 【python】 Get the full set 0 Basics Python Knowledge Manual
reply 【2020】 obtain 2020java Related interview questions tutorial
reply 【 Add group 】 You can join the technical exchange group related to the terminal R & D department
Read more
use Spring Of BeanUtils front , I suggest you understand these pits first !
lazy-mock , A lazy tool for generating backend simulation data
In Huawei Hongmeng OS Try some fresh food , My first one “hello world”, take off !
The byte is bouncing :i++ Is it thread safe ?
One SQL Accidents caused by , Colleagues are fired directly !!
Too much ! Check Alibaba cloud ECS Of CPU Incredibly reach 100%
a vue Write powerful swagger-ui, A little show ( Open source address attached )
Believe in yourself , Nothing is impossible , Only unexpected, not only technology is obtained here !
If you like, just give me “ Looking at ”边栏推荐
- third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
- Hiengine: comparable to the local cloud native memory database engine
- 从零实现深度学习框架——LSTM从理论到实战【实战】
- Xaas trap: all things serve (possible) is not what it really needs
- C application interface development foundation - form control (6) - menu bar, toolbar and status bar controls
- UWB ultra wideband positioning technology, real-time centimeter level high-precision positioning application, ultra wideband transmission technology
- Using repositoryprovider to simplify the value passing of parent-child components
- PHP利用ueditor实现上传图片添加水印
- The city chain technology Digital Innovation Strategy Summit was successfully held
- PG基础篇--逻辑结构管理(用户及权限管理)
猜你喜欢

Force buckle 1200 Minimum absolute difference

C#应用程序界面开发基础——窗体控制(5)——分组类控件

集合

What are the reliable domestic low code development platforms?

Postman core function analysis - parameterization and test report

MMO project learning 1: preheating

【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*

5 years of experience, 27 days of Android programmer interview, 2022 programmer advanced classic

软件测试是干什么的?学习有啥要求?

What does software testing do? What are the requirements for learning?
随机推荐
Common operators and operator priority
What is the function of okcc call center
强化学习-学习笔记4 | Actor-Critic
Oracle fault handling: ora-10873:file * needs to be either taken out of backup or media recovered
Notion 类生产力工具如何选择?Notion 、FlowUs 、Wolai 对比评测
力扣 1200. 最小绝对差
【无标题】
如何在2022年更明智地应用智能合约?
[untitled]
司空见惯 - 英雄扫雷鼠
40000 word Wenshuo operator new & operator delete
Django使用mysqlclient服务连接并写入数据库的操作过程
从零实现深度学习框架——LSTM从理论到实战【实战】
函数的概念及语法
MMO project learning 1: preheating
[AI framework basic technology] automatic derivation mechanism (autograd)
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
No matter how busy you are, you can't forget safety
力扣 729. 我的日程安排表 I
Is it safe for Guohai Securities to open an account online?