Core code analysis of java thread pool framework — to

Original address: http://www.codeceo.com/article/java-thread-pool-kernal.html

In multithreaded programming, it is unrealistic to assign a thread to each task. The overhead of thread creation and resource consumption are very high. Thread pool came into being and became a sharp tool for us to manage threads. Java provides a standard method to decouple the task submission process from the execution process through the interface, and uses runnable to represent the task. Next, let's analyze the implementation of the java thread pool framework ThreadPoolExecutor. The following analysis is based on jdk1 seven

In ThreadPoolExecutor, the upper three bits of capability are used to indicate the running status. They are: running: receiving new tasks and processing tasks in the task queue. Shutdown: not receiving new tasks, but processing tasks in the task queue. Stop: not receiving new tasks, not coming out of the task queue, and interrupting all ongoing tasks. Tidying: all tasks have been terminated, The number of working threads is 0. When it reaches this state, it will execute terminated() terminated: terminated() execution is completed. The state transition diagram ThreadPoolExecutor uses atomic classes to represent the state bits

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>