public class ThreadPoolExecutor extends AbstractExecutorService
Thread pools address two different problems: they usually provide improved performance when executing large numbers of asynchronous tasks, due to reduced per-task invocation overhead, and they provide a means of bounding and managing the resources, including threads, consumed when executing a collection of tasks. Each ThreadPoolExecutor also maintains some basic statistics, such as the number of completed tasks.
Programmers can configure the creation for a thread pool using ThreadPoolExecutor constructor. The following parameters can be configure:
- corePoolSize: This value (core pool size) tells how many threads will be created before implementation (execution policy) starts looking for existing free thread.
- maximumPoolSize: The maximum pool size is the upper bound on how many pool threads can be active at once.
- keepAliveTime: If the pool has more than corePoolSize threads and there are more tasks to execute then implementation (execution policy) will terminate all excess threads (maximumPoolSize – coreThreadSize) which are idle for more than keepAliveTime.
- workQueue: This is a BlockingQueue used for holding tasks awaiting execution. There is direct relation between work queue and pool sizing.