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