当前位置:网站首页>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 ”
边栏推荐
- C#应用程序界面开发基础——窗体控制(5)——分组类控件
- Is it safe for China Galaxy Securities to open an account? Securities account opening
- How to convert word into PDF? Word to PDF simple way to share!
- MMO项目学习一:预热
- Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
- Password reset of MariaDB root user and ordinary user
- Hiengine: comparable to the local cloud native memory database engine
- Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
- What is the function of okcc call center
- Fuzor 2020软件安装包下载及安装教程
猜你喜欢
【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
HiEngine:可媲美本地的云原生内存数据库引擎
Do you know several assertion methods commonly used by JMeter?
Necessary skills for interview in large factories, 2022android will not die, I will not fall
The city chain technology Digital Innovation Strategy Summit was successfully held
Using repositoryprovider to simplify the value passing of parent-child components
使用 RepositoryProvider简化父子组件的传值
【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*
城链科技数字化创新战略峰会圆满召开
随机推荐
Common - Hero Minesweeper
PG basics -- Logical Structure Management (user and permission management)
Float. The specific meaning of the return value of floattorawintbits is to convert float into byte array
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
The difference between ID selector and class selector
Tasks in GStreamer
How MySQL queries and modifies JSON data
手机开户选择哪家券商公司比较好哪家平台更安全
UWB ultra wideband positioning technology, real-time centimeter level high-precision positioning application, ultra wideband transmission technology
Relationship between floating elements and parent and brother boxes
No matter how busy you are, you can't forget safety
众昂矿业:2022年全球萤石行业市场供给现状分析
Postman core function analysis - parameterization and test report
The problem of returning the longtext field in MySQL and its solution
Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
Tutoriel de téléchargement et d'installation du progiciel fuzor 2020
UWB超宽带定位技术,实时厘米级高精度定位应用,超宽带传输技术
Using repositoryprovider to simplify the value passing of parent-child components
安信证券在网上开户安全吗?
MySql中的longtext字段的返回问题及解决