The benefits of a thread pool
1. Reduce the consumption of resources. Reduce the consumption caused by thread creation and destruction by reusing the threads that have been created.
2, improve the response speed. When a task arrives, the task can be executed immediately without waiting for the thread to be created.
3, improve the manageability of threads.
Threads in a thread pool are called worker threads
Iii. Several common Java thread pools
1. Fixedthreadpool is a typical and excellent thread pool that has the advantage of thread pooling to increase program efficiency and save the overhead of creating threads. When an online pool is idle, that is, there is no running task in the thread pool, it does not release the worker thread and consumes some system resources.
2. The Cachedthreadpool feature is that when an online pool is idle, that is, when there is no running task in the thread pool, it frees the worker thread and frees up the resources that the worker thread occupies. However, when a new task occurs, it is also necessary to create a fresh worker thread with a certain amount of overhead. Also, when using Cachedthreadpool, be sure to pay attention to the number of control tasks, otherwise, because a large number of threads running at the same time, it will cause system paralysis.
3,newschedulethreadexecutor size unlimited thread pool, support timed and periodic execution threads
Java thread Pool