Related Articles Directory:
Java thread pool Threadpoolexecutor usage and analysis (i)
Java thread pool Threadpoolexecutor usage and Analysis (ii)-execute () principle
Java thread pool Threadpoolexecutor usage and Analysis (iii)-end thread pool principle
Execute () is the only method in the Java.util.concurrent.Executor interface, which is described in the JDK annotation as "executing command commands at some point in the future", that is, submitting a task to a thread pool and executing it at some point in the future, The submitted task must implement the Runnable interface, which cannot get the return value. The following is an analysis of the internal principles of the Execute () method, which briefly describes the state of the thread pool, and involves the determination of the thread pool State in a series of executions. The following analysis is based on JDK 1.7
The following is a table of contents outline for this article:
One, the thread pool execution process
Second, thread pool status
Iii. internal principles of task submission
1, execute ()--Submit the task
2, Addworker ()--Add worker thread
3. Internal class worker
4, Runworker ()--Perform the task
5, Gettask ()--Get the task
6, Processworkerexit ()--worker thread exits
If there are any mistakes please forgive and welcome to criticize and discuss with each other.
Please respect the results of the work of the author, reproduced please indicate the original link:
http://www.cnblogs.com/trust-freedom/p/6681948.html One, thread pool execution flow
1. Create a new thread to perform a newly added task if the number of threads in the thread pool is less than corepoolsize
2. If the number of threads in the thread pool is greater than or equal to corepoolsize, but the queue workqueue is not full, the newly added task is placed in the Workqueue
3. If the number of threads in the thread pool is greater than or equal to corepoolsize and the queue Workqueue full, but the number of threads in the thread pool is less than maximumpoolsize, a new thread is created to handle the added task
4, if the number of threads in the thread pool equals maximumpoolsize, use Rejectedexecutionhandler to execute reject policy two, thread pool state
| 1 2 3 4, 5 6 7 8 9 10 11 12 13 14 15 |
Private final Atomicinteger ctl = new Atomicinteger (Ctlof (RUNNING, 0)); private static final int count_bits = integer.size-3; |