Java thread pool Threadpoolexecutor usage and Analysis (ii)-execute () principle __java

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.