Spring thread pool threadpooltaskexecutor configuration details
This article introduces the configuration of spring thread pool threadpooltaskexecutor and shares it with you as follows:
1. Threadpooltaskexecutor configuration
Attribute field description
Corepoolsize: the minimum number of threads maintained by the thread pool
Keepaliveseconds: allowed idle time
Maxpoolsize: the maximum number of thread pool maintenance threads
Queuecapacity: cache queue
Rejectedexecutionhandler: processing policy for rejecting tasks
2. Execute (runable) method execution process
If the number of threads in the thread pool is less than corepoolsize at this time, even if the threads in the thread pool are idle, a new thread should be created to process the added task.
If the number of threads in the thread pool is equal to corepoolsize at this time, but the buffer queue workqueue is not full, the task is put into the buffer queue.
If the number of threads in the thread pool is greater than corepoolsize, the buffer queue workqueue is full, and the number of threads in the thread pool is less than maxpoolsize, a new thread is created to process the added task.
If the number in the thread pool is greater than corepoolsize, the buffer queue workqueue is full, and the number in the thread pool is equal to maxpoolsize, the task is processed through the policy specified by the handler. That is, the priority of processing tasks is: core thread corepoolsize, task queue workqueue and maximum thread maximumpoolsize. If all three are full, use handler to process rejected tasks.
When the number of threads in the thread pool is greater than corepoolsize, if a thread is idle for more than keepalivetime, the thread will be terminated. In this way, the thread pool can dynamically adjust the number of threads in the pool.
3. Example code
Junit Test
MultiThreadDemo
MultiThreadProcessService
MultiThreadConfig
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.