Five kinds of features and functions common thread pool

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/yjn1995/article/details/100574850

newCachedThreadPool

Role: to create a thread pool may need to create a new thread, but they will reuse previously constructed threads when available and when required for use provided ThreadFactory to create a new thread.
Wherein:
(1) There is no fixed number of threads in the pool may reach a maximum value (Interger MAX_VALUE.)
Threads (2) may be cached thread pool reuse and recycling (recycling default time of 1 min)
(3) when the thread pool , there are no available threads, will re-create a thread

newFixedThreadPool

Role: Creates a thread pool that reuses a fixed number of threads to a shared unbounded queue to run these threads. At any point, in most nThreads thread is active processing tasks. If you submit additional task when all threads are active, before you have available threads, additional tasks will wait in the queue. If during the execution before the closure due to a failure of any thread terminates, then replace it with a new thread to execute subsequent tasks (if needed). Before a thread is explicitly closed, the thread pool will always exist.
Wherein:
the thread (1) of the thread pool at a certain amount, can be well controlled amount of concurrent threads
(2) thread can be repeated used, prior to display off, will persist
(3) exceeds a certain amount of threads when submitted to wait in the queue

newSingleThreadExecutor

Role: Creates an Executor that uses a single worker thread to unbounded queue to run this thread. (Note that if a failure occurs during execution because before the closure and termination of this single thread, if necessary, replace it with a new thread will execute subsequent tasks). You can ensure the implementation of each task in sequence, and at any given time there will be no more than one thread is active. Unlike other equivalent newFixedThreadPool (1), you can be guaranteed without having to reconfigure this method returns program execution to the other thread.
Features:
execute a thread (1) up to the thread pool, thread activity after the submission of this row will be executed in the queue

newScheduledThread

Role: Creates a thread pool that can schedule in order to run after a given delay, or to execute periodically.
Wherein:
(1) having a specified number of threads in the pool of threads, thread, even if empty will be retained
(2) can be timed or delayed execution thread activity

newSingleScheduledThread

Role: to create a single-threaded executor that can schedule in order to run after a given delay, or to execute periodically.
Wherein:
performing a thread (1) up to the thread pool, thread activity after filing in the queue will be executed in order
(2) can be timed or delayed execution thread activity

Guess you like

Origin blog.csdn.net/yjn1995/article/details/100574850