当前位置:网站首页>[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
边栏推荐
- The final week, I split
- 在已经知道表格列勾选一个显示一列
- tars源码分析之1
- 请问旧版的的常用SQL怎么迁移到新版本里来?
- MySQL 45 lecture learning notes (XIV) count (*)
- 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 to share the source code anti disclosure scheme
- What is Gibson's law?
- 关于IDEA如何设置快捷键集
- Why does the producer / consumer mode wait () use while instead of if (clear and understandable)
猜你喜欢
selenium驱动IE常见问题解决Message: Currently focused window has been closed.
校园网络问题
Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
Campus network problems
Deep understanding of redis -- a new type of bitmap / hyperloglgo / Geo
MySQL 45 lecture learning notes (VII) line lock
GoogleChromePortable 谷歌chrome浏览器便携版官网下载方式
Can the out of sequence message complete TCP three handshakes
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
Introduction to spark core components
随机推荐
Introduction to spark core components
CORS is not intended to protect API endpoints - nikofischer
Knowledge payment applet dream vending machine V2
How does the inner roll break?
Set JTAG fuc invalid to normal IO port
Finishing (III) - Exercise 2
请问旧版的的常用SQL怎么迁移到新版本里来?
Latex中的单引号,双引号如何输入?
Wechat applet scroll view component scrollable view area
Redis面试题集
图的底部问题
What is Gibson's law?
Analysis of tars source code 1
Highly paid programmers & interview questions: how does redis of series 119 realize distributed locks?
regular expression
Mysql 45讲学习笔记(十三)表数据删掉一半,表文件大小不变
Can the out of sequence message complete TCP three handshakes
[backpack DP] backpack problem
[number theory] fast power (Euler power)
uniapp小程序分包