当前位置:网站首页>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 ”
边栏推荐
- S7-200SMART利用V90 MODBUS通信控制库控制V90伺服的具体方法和步骤
- Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
- The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
- openh264解码数据流向分析
- How to apply smart contracts more wisely in 2022?
- Recommended collection, my Tencent Android interview experience sharing
- 【硬核干货】数据分析哪家强?选Pandas还是选SQL
- 如何在2022年更明智地应用智能合约?
- Gstreamer中的task
- Add data to excel small and medium-sized cases through poi
猜你喜欢
Common - Hero Minesweeper
[hard core dry goods] which company is better in data analysis? Choose pandas or SQL
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
测试的核心价值到底是什么?
Reinforcement learning - learning notes 4 | actor critical
再忙不能忘安全
Bitcoinwin (BCW) was invited to attend Hanoi traders fair 2022
What are the reliable domestic low code development platforms?
Hiengine: comparable to the local cloud native memory database engine
随机推荐
Is it safe for China Galaxy Securities to open an account? Securities account opening
That's awesome. It's enough to read this article
Inventory of the most complete low code / no code platforms in the whole network: Jiandao cloud, partner cloud, Mingdao cloud, Qingliu, xurong cloud, Jijian cloud, treelab, nailing · Yida, Tencent clo
Debezium系列之:修改源码支持unix_timestamp() as DEFAULT value
安信证券在网上开户安全吗?
Summer Challenge database Xueba notes, quick review of exams / interviews~
How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI
Fuzor 2020軟件安裝包下載及安裝教程
redis集群模拟消息队列
Redis cluster simulated message queue
What are the reliable domestic low code development platforms?
测试外包公司怎么样?
The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
C#应用程序界面开发基础——窗体控制(6)——菜单栏、工具栏和状态栏控件
IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍
The city chain technology Digital Innovation Strategy Summit was successfully held
PG基础篇--逻辑结构管理(用户及权限管理)
How about testing outsourcing companies?
Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
司空见惯 - 英雄扫雷鼠