Java Concurrency Programming-executor framework Set

Source: Internet
Author: User

The executor framework encapsulates thread scheduling and Decouples task submissions from task execution.

It provides all the methods of thread lifecycle scheduling, greatly simplifying the threshold for thread scheduling and synchronization.

The core class diagram for the executor frameset is as follows:


From the top down, you can clearly see the various classes of the frameset, and the relationships between them:
Executor, is an object that can commit an executable (Runnable) task, which decouples the task submission and execution details (thread usage, scheduling, etc.), and Executor is used primarily to replace the displayed creation and running threads;
Executorservice provides an asynchronous way to manage one or more thread terminations, the execution process (future);
Abstractexecutorservice provides a default implementation of Executorservice, which implements the submit, Invokeany, by runnablefuture (Implementation class Futuretask), InvokeAll several methods;
Threadpoolexecutor is a configurable thread pool implementation of Executorservice, which has two important configuration parameters: Corepoolsize (the basic size of the thread pool, the size of the thread pool when no tasks need to be performed, Threads that exceed this number are created only if the work queue is full. It is important to note that the thread does not start immediately when the Threadpoolexecutor is created, but is not started until a task is committed, unless prestartcorethread/is called Prestartallcorethreads boot the core thread beforehand. Considering the effects of the KeepAliveTime and allowcorethreadtimeout timeout parameters, the size of the thread pool is not necessarily corepoolsize when there is no task to execute. ), maximumpoolsize (the maximum number of threads allowed in the thread pool, the current number of threads in the thread pool does not exceed this value.) If the task in the queue is full and the current number of threads is less than maximumpoolsize, a new thread is created to perform the task. What is worth mentioning here is Largestpoolsize, which records the maximum number of threads that the thread pool has ever seen throughout its life cycle. Why did you say it once? Because the thread pool is created, you can call Setmaximumpoolsize () to change the maximum number of threads that are running. );
Scheduledexecutorservice is a executorservice that adds a scheduling feature (delay or timed execution);
Scheduledthreadpoolexecutor is a pooling implementation of executorservice with scheduling characteristics.
Executors is a executor, Executorservice, Scheduledexecutorservice, threadfactory, callable tool class that can meet most of the daily application scenarios. Use it to create a thread pool:

Java Concurrency Programming-executor framework Set

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.