当前位置:网站首页>[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
边栏推荐
- Background and current situation of domestic CDN acceleration
- tcp socket 的 recv 如何接收指定长度消息?
- How to input single quotation marks and double quotation marks in latex?
- selenium驱动IE常见问题解决Message: Currently focused window has been closed.
- The final week, I split
- tars源码分析之2
- the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
- Tar source code analysis 4
- Responsive - media query
- The most effective futures trend strategy: futures reverse merchandising
猜你喜欢

The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native

the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘

Fundamentals of SQL database operation

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

图的底部问题

Another company raised the price of SAIC Roewe new energy products from March 1

Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture

MySQL relearn 2- Alibaba cloud server CentOS installation mysql8.0

what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!

The important role of host reinforcement concept in medical industry
随机推荐
Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
MySQL 45 lecture learning notes (VII) line lock
[backpack DP] backpack problem
Code rant: from hard coding to configurable, rule engine, low code DSL complexity clock
Software keywords and process information intercepted by Golden Shield video player
【网络数据传输】基于FPGA的百兆网/兆网千UDP数据包收发系统开发,PC到FPGA
Mysql 45讲学习笔记(十)force index
云Redis 有什么用? 云redis怎么用?
CMS source code of multi wechat management system developed based on thinkphp6, with one click curd and other functions
selenium IDE插件下载安装使用教程
Another company raised the price of SAIC Roewe new energy products from March 1
Industrial computer anti-virus
响应式移动Web测试题
[FPGA tutorial case 7] design and implementation of counter based on Verilog
What is industrial computer encryption and how to do it
Latex中的单引号,双引号如何输入?
Four sets of APIs for queues
期末周,我裂开
NLP-文献阅读总结
Shopping malls, storerooms, flat display, user-defined maps can also be played like this!