1. Thread pool
(1) advantages of thread pool:
- reuse threads in the thread pool to avoid the performance overhead associated with creating and destroying threads.
- It can effectively control the maximum concurrency of the thread pool, and avoids the blocking phenomenon caused by the large number of threads that preempt the system resources.
- enables simple management of threads and provides functions such as timed execution and specified interval loop execution.
(2) thread pool in Android:
The concept of a thread pool in Android comes from Executor,executor in Java as an excuse, and the real thread pool is implemented as Threadpoolexecutor.
Threadpoolexecutor provides a set of parameters to configure the thread pool, with different parameters to create different thread pools .
From the functional characteristics of the thread pool, the Android thread pool is divided into 4 classes , which can be obtained by the factory method provided by executor. 4 Class thread pools.
Since the thread pool in Android is implemented directly or indirectly by configuring Threadpoolexecutor , we'll introduce threadpoolexecutor here.
2. Threadpoolexecutor
Threadpoolexecutor is the real implementation of the thread pool, and its construction method provides a set of parameters to configure the thread pool.
The following describes the meaning of each parameter in Threadpoolexecutor's constructor, which will directly affect the function of the thread pool, and a more common construction method below Threadpoolexecutor:
Android (Java) Learning Note 267:android thread pool