Reference
The cost of the system to start a new thread is relatively high because it involves interacting with the operating system. Using a thread pool can improve performance, especially if you need to consider using thread pooling when you want to create a lot of short-lived threads in your program. The thread pool creates a large number of idle threads at system startup, the program passes a Runnable object or callable object to the thread pool, and the thread pool initiates a thread to execute their run () or call () methods, and when the run () or call () method finishes executing, The thread does not die, but returns to the thread pool again to become idle, waiting to execute the next Runnable object's run () or call () method.
The thread pool can also effectively control the number of concurrent threads in the system, and when the system contains a large number of concurrent threads, it can cause severe system performance degradation or even a JVM crash, while the thread pool's maximum number of threads parameter controls the number of concurrent threads in the system.
JAVA5 thread Pool
Java5 built-in thread pool, the Executors factory class was added to generate the thread pool, which contains several static factory methods to create the threading pools.
Executorservice Newcachedthreadpool () creates a buffer-capable thread pool
Executorservice Newfixedthreadpool (int n) creates a reusable thread pool with a fixed number of threads
Executorservice Newsinglethreadexecutor () Create a thread pool that is single thread, same as Newfixedthreadpool (1)
Scheduledexecutorservice newscheduledthreadpool (int corepoolsize) creates a thread pool with the specified number of threads, which can perform the threading task after a specified delay.
Scheduledexecutorservice Newsinglethreadscheduledexecutor () creates a thread pool with only one number of threads, which can perform thread tasks after a specified delay.
The executorservice represents a thread pool that executes threads as soon as possible (thread tasks are performed as long as there are idle thread pools in the pool of threads).
Scheduledexecutorservice represents a thread pool that can execute thread tasks after a specified delay or periodically.
Multithreading-executor,executors,executorservice,scheduledexecutorservice,abstractexecutorservice