当前位置:网站首页>[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
边栏推荐
- tars源码分析之8
- tars源码分析之2
- the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
- Set JTAG fuc invalid to normal IO port
- Fundamentals of SQL database operation
- centos8安装mysql.7 无法开机启动
- What is tweeman's law?
- What is industrial computer encryption and how to do it
- the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
- CORS is not intended to protect API endpoints - nikofischer
猜你喜欢

Cervical vertebra, beriberi

The most effective futures trend strategy: futures reverse merchandising

响应式移动Web测试题

MySQL 45 lecture learning notes (VII) line lock

regular expression

Mysql 45讲学习笔记(七)行锁

Mobile adaptation: vw/vh

Deep understanding of redis -- a new type of bitmap / hyperloglgo / Geo

List of top ten professional skills required for data science work

Wechat applet scroll view component scrollable view area
随机推荐
2022 wechat enterprise mailbox login entry introduction, how to open and register enterprise wechat enterprise mailbox?
期末周,我裂开
颈椎、脚气
[FPGA tutorial case 8] design and implementation of frequency divider based on Verilog
How does the recv of TCP socket receive messages of specified length?
thread priority
What is the sheji principle?
Wechat applet scroll view component scrollable view area
Boast about Devops
GoogleChromePortable 谷歌chrome浏览器便携版官网下载方式
leetcode825. 适龄的朋友
selenium驱动IE常见问题解决Message: Currently focused window has been closed.
The sorting in C language realizes the number sorting method from small to large
tars源码分析之9
Knowledge payment applet dream vending machine V2
leetcode 310. Minimum Height Trees
How to share the source code anti disclosure scheme
Selection (021) - what is the output of the following code?
【问题记录】03 连接MySQL数据库提示:1040 Too many connections
Analysis of tars source code 5