concept thread pool in category android

This is an excerpt from Manning's book Android in Practice.
The solution here is to use a thread pool. A thread pool is a set of threads that are managed in a controlled environment, for instance by setting an upper limit on the number of threads and by forcing the application to reuse threads and distribute the workload among them.
Thread pools in Java and Android are controlled through a ThreadPoolExecutor. A ThreadPoolExecutor is an object that can schedule and manage tasks. Tasks are described by Runnable objects, and are executed in threads taken from a thread pool. This sounds complicated, but it’s completely transparent to the developer. Use the executor to start a task and let the executor do the heavy lifting (see figure 6.8).
Figure 6.8. The application posts a Runnable to the executor, which then schedules it for execution. As soon as a thread becomes available, it’s taken from the pool and used to execute the Runnable.
![]()
Thread pools can be configured in various ways, from the lower and upper bound of threads they run to the scheduling rules by which tasks will be distributed among all threads. A commonly used kind of thread pool is one that manages a fixed number of threads that execute tasks posted to a shared queue. If there are more tasks than threads, tasks will have to wait until a thread completes its work and becomes available.