Detailed explanation of custom thread pool ThreadPoolExecutor

Detailed explanation of custom thread pool ThreadPoolExecutor

References (Alibaba Java Development Manual Songshan Edition): https://developer.aliyun.com/topic/java20

References: https://blog.csdn.net/ming1215919/article/details/114799184

Thread Pool

The job of the thread pool is mainly to control the number of running threads, put tasks into the queue during processing, and then start these tasks after the threads are created. If the number of threads exceeds the maximum number, then the excess number of threads waits in line for other threads After the execution is completed, the task is taken out of the queue for execution.

During the development process, reasonable use of the thread pool can bring three benefits:

  • **Reduce resource consumption. **Reduce the consumption caused by thread creation and destruction by reusing the created thread;

  • ** Improve responsiveness. **When the task arrives, the task can be executed immediately without waiting for the thread to be created;

  • ** Improve thread manageability. **Threads are scarce resources. If created without limit, it will not only consume system resources, but also reduce the stability of the system. Using the thread pool can be used for unified allocation, tuning and monitoring.

Guess you like

Origin blog.csdn.net/sinat_36184075/article/details/129276823