Executors class provides a series of factory methods for creating a thread pool, and the returned thread pool implements the executorservice interface.
1. newfixedthreadpool
Public static executorservice newfixedthreadpool (INT nthreads );
Public static executorservice newfixedthreadpool (INT nthreads, threadfactory)
Create a thread pool that can reuse a set of fixed threads and run these threads in a shared, unbounded queue mode. If any thread is terminated due to a failure during the execution before it is disabled, a new thread will execute subsequent tasks (if needed) in place of it ).
2. newsinglethreadexecutor
Public static executorservice newsinglethreadexecutor ();
Public static executorservice newsinglethreadexecutor (threadfactory );
Create an executor that uses a single worker thread to run this thread in an unbounded queue mode. (Note: If this single thread is terminated because of a failure during the execution before it is disabled, a new thread will execute subsequent tasks in place of it if needed ). The tasks can be executed sequentially, and no threads are active at any given time. Unlike other equivalent newfixedthreadpool (1), other threads can be used without the need to reconfigure the execution program returned by this method.
3. newcachedthreadpool
Public static executorservice newcachedthreadpool ();
Public static executorservice newcachedthreadpool (threadfactory );
Create a thread pool where new threads can be created as needed, but they will be reused when previously constructed threads are available. For programs that execute many short-term asynchronous tasks, these thread pools can usually improve program performance. Calling execute will reuse the previously constructed thread (if the thread is available ). If the existing thread is not available, create a new thread and add it to the pool. Terminate and Remove unused threads from the cache for 60 seconds. Therefore, a thread pool that remains idle for a long time does not use any resources. Note: You can use the threadpoolexecutor constructor to create a thread pool with similar attributes but different details (such as timeout parameters.
4. newscheduledthreadpool
Public static scheduledexecutorservice newscheduledthreadpool (INT corepoolsize );
Public static scheduledexecutorservice newscheduledthreadpool (INT corepoolsize, threadfactory );
Create a thread pool that can be scheduled to run commands or periodically after a given delay.
5. newsinglethreadscheduledexecutor
Public static scheduledexecutorservice newsinglethreadscheduledexecutor ();
Public static scheduledexecutorservice newsinglethreadscheduledexecutor (threadfactory );
Create a single-threaded execution program that can be scheduled to run commands or regularly after a given delay. (Note: If a single thread is terminated due to a failure during the execution before it is disabled, a new thread will execute subsequent tasks in place of it if necessary ). The tasks can be executed sequentially, and no threads are active at any given time. Unlike other equivalent newscheduledthreadpool (1), other threads can be used without the need to reconfigure the execution program returned by this method.