当前位置:网站首页>[thread pool]
[thread pool]
2022-07-04 06:56:00 【No trace after wind 2018】
Thread pool
Main parameters of thread pool

7 Big parameters
- corePoolSize: Number of core threads , Number of resident core threads in the thread pool
After creating the thread pool , When a request comes , The thread in the pool will be arranged to perform the request task , Approximately understood as the thread on duty today
When the number of threads in the thread pool reaches corePoolSize after , The arrival queue will be put into the cache queue - maximumPoolSize: The thread pool can hold the maximum number of threads executing at the same time , This value must be greater than or equal to 1
Quite a number of threads after capacity expansion , The maximum number of threads this thread pool can hold - keepAliveTime: Extra idle thread lifetime
When the number of thread pools exceeds corePoolSize when , When the free time reaches keepAliveTime When the value of , Redundant idle threads will be destroyed , Until there is only corePoolSize Up to threads
By default , Only if the number of threads in the thread pool is greater than corePoolSize when ,keepAliveTime It works - unit:keepAliveTime The unit of
- workQueue: Task queue , Tasks submitted but not executed ( It's like a waiting area in a bank )
LinkedBlockingQueue: The linked list blocks the queue
SynchronousBlockingQueue: Synchronous blocking queue - threadFactory: Represents the thread factory that generates the worker threads in the thread pool , Used to create a thread pool Generally, you can use default
- handler: Refusal strategy , Indicates that when the queue is full and the worker thread is greater than the maximum number of threads in the thread pool (maximumPoolSize3) when , How to refuse the request to execute Runnable The strategy of

How the underlying thread pool works
Thread pool operation architecture diagram 
The main processing flow of thread pool 
A caption
- After the thread pool is created , Waiting for the task request submitted
- When calling execute() Method to add a request task , The thread pool will make the following judgment
2.1 If the number of running thread pools is less than corePoolSize, Now create a thread to run the task
2.2 If the number of running threads is greater than or equal to corePoolSize, Put the task in the queue
2.3 If the queue is full at this time , And the number of running threads is less than maximumPoolSize, Then create a non core thread like Run this task ;
2.4 If the queue is full and the number of running threads is greater than or equal to maximumPoolSize, Then the thread pool will start the saturation rejection policy to execute - When a thread completes a task , It takes a task from the queue to execute
- When a thread has nothing to do for a certain time (keepAliveTime) when , Thread pool will judge :
4.1 If the number of threads currently running is greater than corePoolSize, Then the thread is stopped
4.2 So after all tasks of thread pool are completed , It will eventually shrink to corePoolSize Size
Rejection policy for thread pool
Waiting thread is full ,max Threads have also reached , Unable to service new task , You need a rejection strategy to solve
- AbortPolicy: Default , Direct selling RejectedExcutionException abnormal , Prevent the system from working properly
- DiscardPolicy: Discard tasks directly , No processing and no exception thrown , If the running task is lost , It's a good plan
- CallerRunsPolicy: The strategy will not abandon the task , It doesn't throw an exception , Instead, some tasks are rolled back to the caller
- DiscardOldestPolicy: Discard the task waiting the longest in the queue , Then add the current task to the queue and try to submit the current task again
边栏推荐
- Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
- [FPGA tutorial case 7] design and implementation of counter based on Verilog
- MySQL 45 lecture learning notes (VI) global lock
- A new understanding of how to encrypt industrial computers: host reinforcement application
- What is a spotlight effect?
- Tar source code analysis Part 2
- Uniapp applet subcontracting
- MySQL 45 lecture learning notes (12) MySQL will "shake" for a while
- JS common time processing functions
- 2022年,或许是未来10年经济最好的一年,2022年你毕业了吗?毕业后是怎么计划的?
猜你喜欢

用于压缩视频感知增强的多目标网络自适应时空融合

NLP-文献阅读总结

移动适配:vw/vh

Industrial computer anti-virus

Introduction to spark core components

2022 wechat enterprise mailbox login entry introduction, how to open and register enterprise wechat enterprise mailbox?

Selenium driver ie common problem solving message: currently focused window has been closed

关于IDEA如何设置快捷键集

Crawler (III) crawling house prices in Tianjin

List of top ten professional skills required for data science work
随机推荐
tars源码分析之3
Tar source code analysis Part 10
Su Weijie, a member of Qingyuan Association and an assistant professor at the University of Pennsylvania, won the first Siam Youth Award for data science, focusing on privacy data protection, etc
【FPGA教程案例8】基于verilog的分频器设计与实现
Analysis of tars source code 5
移动适配:vw/vh
Latex中的单引号,双引号如何输入?
Background and current situation of domestic CDN acceleration
Industrial computer anti-virus
Novel website program source code that can be automatically collected
Knowledge payment applet dream vending machine V2
tars源码分析之9
2022 is probably the best year for the economy in the next 10 years. Did you graduate in 2022? What is the plan after graduation?
How notepad++ counts words
uniapp小程序分包
Displaying currency in Indian numbering format
Mobile adaptation: vw/vh
CMS source code of multi wechat management system developed based on thinkphp6, with one click curd and other functions
Can the out of sequence message complete TCP three handshakes
selenium IDE插件下载安装使用教程