Executor is a top-level interface in which only one method execute (Runnable) is declared, the return value is void, the argument is of type Runnable,
The literal meaning can be understood, is used to carry out the mission;
Then the Executorservice interface inherits the executor interface and declares some methods: Submit, InvokeAll, Invokeany and shutdown, etc.
Abstract class Abstractexecutorservice implements the Executorservice interface, which basically implements all the methods declared in Executorservice;
Then Threadpoolexecutor inherits the class Abstractexecutorservice.
executors The following static methods are available in this tool class:
- Executors.newCachedThreadPool () infinite size thread pool, threads are automatically reused
- Executors.newfixed ThreadPool (int) thread pool to fix the number of threads
- Executors.newsingle threadexecutor () mono-thread Actuator
According to several factory methods in the Executors class, respectively, the following are used:
- Linkedblockingqueue. Fixedthreadpool and Singlethreadexecutor Use this blockingqueue, the queue length is unbounded, and is suitable for submitting tasks that are independent of each other's dependent scenarios.
- Synchronousqueue. Cachedthreadpool uses this blockingqueue, which usually requires the thread pool not to set the maximum number of threads to ensure that the submitted task will be executed without being discarded. This is usually a scenario that is suitable for tasks that depend on each other.
Of course, developers can also customize Threadpoolexecutor when using arrayblockingqueue bounded queues
Java thread pool [go]