ThreadPoolExecutor is the core implementation of Java's Executor framework that efficiently manages task execution using a pool of reusable worker threads. Instead of creating a new thread for every task, it controls thread creation, task queuing, execution, and termination, resulting in better performance and resource utilization.
1. Task Submission
2. Core Thread Creation
3. Task Queueing
4. Non-Core Thread Creation
5. Rejection Handling
In an online shopping application, thousands of order-processing requests may arrive simultaneously. ThreadPoolExecutor reuses a limited number of threads, queues excess requests, and prevents the system from being overwhelmed by creating uncontrolled numbers of threads.
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class ThreadPoolDemo {
public static void main(String[] args) {
ThreadPoolExecutor executor =
new ThreadPoolExecutor(
2,
5,
60,
TimeUnit.SECONDS,
new LinkedBlockingQueue<>(10)
);
executor.execute(() ->
System.out.println(
"Task Executed"));
System.out.println(
"Pool Size : "
+ executor.getPoolSize());
System.out.println(
"Active Threads : "
+ executor.getActiveCount());
executor.shutdown();
}
}A concise interview answer is: ThreadPoolExecutor manages tasks by first assigning them to core threads, then storing them in a work queue, and finally creating additional threads up to maximumPoolSize when needed. It transitions through RUNNING, SHUTDOWN, STOP, TIDYING, and TERMINATED states to control task execution and thread lifecycle efficiently.
Last updated: 1 November 2026
Previous question: What is the difference between visibility and atomicity in multithreading?
Next question: How is memory allocated on the heap, and is the heap size fixed?