Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

What do Executors.newFixedThreadPool, newCachedThreadPool and newSingleThreadExecutor create, and what hidden risk does each carry?

newFixedThreadPool(n) creates n threads with an unbounded LinkedBlockingQueue, so under overload tasks pile up without limit until memory runs out. newCachedThreadPool has zero core threads, an unlimited maximum, a SynchronousQueue and a 60-second idle timeout, so a burst can create thousands of threads. newSingleThreadExecutor runs tasks one at a time on one thread with an unbounded queue, with the same pile-up risk and a single point of slowness. For production services we construct ThreadPoolExecutor directly with bounded queues, named threads and an explicit rejection policy, while Executors.newVirtualThreadPerTaskExecutor() starts a new virtual thread per task.

Why this question is asked

The Executors factory methods are the first thing most of us learn about thread pools, and they are still all over production code. Each one makes a reasonable choice for a demo and a risky one for a service under load, and the risk is hidden inside the constructor arguments. Interviewers ask this to see whether we know what each method really builds and can explain the failure mode before it happens. In this answer, we will open up each of the three factory methods, see the hidden risk in each one, build a production-ready pool by hand, and look at where the virtual-thread executor fits.

1A Quick Recap of ThreadPoolExecutor

All three factory methods return a ThreadPoolExecutor configured in a particular way. Its main settings are the core pool size, the number of threads it keeps; the maximum pool size; the keep-alive time after which extra idle threads end; the work queue that holds tasks waiting for a thread; and the rejection policy for tasks it cannot accept. When a task arrives, the pool creates a thread if it has fewer than core threads, otherwise puts the task in the queue, and only if the queue refuses it creates extra threads up to the maximum. That order explains every risk below.

2NewFixedThreadPool: A Queue Without a Limit

Executors.newFixedThreadPool(n) is new ThreadPoolExecutor(n, n, 0, MILLISECONDS, new LinkedBlockingQueue<>()). It keeps exactly n threads, and the queue has no capacity limit, about two billion entries. Under normal load that is fine. Under overload, when tasks arrive faster than n threads finish them, nothing ever says no: the queue grows by the difference every second, each queued task holds its captured data, and latency for new tasks grows with the queue length. The service becomes slow first and then fails with OutOfMemoryError, often minutes after the overload started, which makes the cause hard to see.

Java
ExecutorService pool = Executors.newFixedThreadPool(8);
// 8 threads; each task takes 100 ms -> capacity 80 tasks per second
// 200 tasks arrive per second -> queue grows by 120 per second
// after 10 minutes: about 72,000 queued tasks, each waiting about 15 minutes

3NewCachedThreadPool: Threads Without a Limit

Executors.newCachedThreadPool() is new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, SECONDS, new SynchronousQueue<>()). A SynchronousQueue has no capacity; it only hands a task directly to a thread that is waiting for one. So if no thread is idle, the offer fails and the pool creates a new thread, with no upper bound. Idle threads end after 60 seconds.

For many short tasks arriving at a steady rate, this reuses a small set of threads nicely. The risk appears with slow tasks or bursts: if tasks block on a slow downstream call for 2 seconds and 1,000 arrive per second, the pool grows to around 2,000 platform threads, each with its own stack, often 1 MB of reserved address space by default and real memory for what it uses. The operating system's thread limit, memory, or context-switch overhead gives out before the pool does. A cached pool converts load directly into threads.

4NewSingleThreadExecutor: One at a Time, Still Unbounded

Executors.newSingleThreadExecutor() is a pool of one thread with an unbounded LinkedBlockingQueue, wrapped so that its size cannot be changed later. It guarantees that tasks run sequentially in submission order, which is useful for work that must not run concurrently, such as writing to one file. If its thread dies from an exception in a task, the pool creates a replacement so later tasks still run.

Its risks are those of the fixed pool, plus one: a single slow or stuck task delays everything behind it. If one task blocks on a network call without a timeout, the whole executor stops, and the queue grows silently.

What the factory methods build
Factory methodThreads and queueHidden risk
newFixedThreadPool(n)n threads, unbounded LinkedBlockingQueueQueue grows until OOM
newCachedThreadPool()0 to unlimited threads, SynchronousQueue, 60 s idleThousands of threads in a burst
newSingleThreadExecutor()1 thread, unbounded queueQueue growth; one stuck task stops all
newVirtualThreadPerTaskExecutor()New virtual thread per task, no queueNo limit on concurrency downstream

5Building a Production Pool by Hand

In a service we want every limit to be a decision. Constructing ThreadPoolExecutor directly makes us choose the queue capacity, name the threads so thread dumps and logs show which pool they belong to, and decide what happens when the pool is full.

Java
ThreadFactory factory = Thread.ofPlatform().name("report-worker-", 0).factory(); // report-worker-0, -1 ...
ThreadPoolExecutor reports = new ThreadPoolExecutor(
8, 8, // core and max: 8 threads
60, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(500), // at most 500 waiting tasks
factory,
new ThreadPoolExecutor.AbortPolicy()); // full -> RejectedExecutionException
// the caller turns rejection into a clear answer, for example HTTP 503
try {
reports.execute(task);
} catch (RejectedExecutionException e) {
throw new ServiceBusyException("report queue full");
}

Notice the reasons for each choice. The bounded queue turns overload into an immediate, visible rejection instead of a slow memory leak. The rejection policy decides who pays: AbortPolicy fails the caller, while CallerRunsPolicy runs the task on the submitting thread, which slows the producer down and acts as back pressure. Named threads make 'report-worker-3' show up in a thread dump instead of 'pool-7-thread-3'. In Spring, ThreadPoolTaskExecutor wraps the same settings with properties such as queue capacity and thread name prefix, and manages shutdown with the application context.

6Where the Virtual-Thread Executor Fits

Executors.newVirtualThreadPerTaskExecutor(), final since Java 21, does not pool at all: it starts a new virtual thread for each task. Virtual threads are cheap, a few hundred bytes to a few kilobytes each, and blocking one does not block an operating-system thread, so a million concurrent tasks is feasible for I/O-bound work. That removes the main reason pools existed. What it does not remove is the need to limit concurrency towards downstream systems: a million virtual threads can still open a million database requests. So with virtual threads we express limits directly, for example with a Semaphore or the size of a connection pool, rather than through the number of threads.

7Follow-up questions

Is Executors.newWorkStealingPool different?

Yes. It returns a ForkJoinPool with parallelism equal to the number of processors by default, where each worker has its own deque and idle workers steal tasks from others. It suits many small CPU-bound tasks and does not guarantee execution order. It also has no bounded submission queue, so overload behaves like the fixed pool.

Why not just use a very large fixed pool?

A large fixed pool still has an unbounded queue, and many platform threads cost memory and context switches. The size should reflect what the work needs, such as CPU count for CPU-bound tasks or the downstream connection limit for I/O, with a bounded queue in front.

Do these executors need to be shut down?

Yes. Their threads are non-daemon, so an executor that is never shut down keeps its threads alive and can stop the JVM from exiting. Since Java 19, ExecutorService implements AutoCloseable, so try-with-resources works for short-lived executors, and long-lived ones should be shut down with the application.

8Conclusion

In this answer, we opened up the Executors factory methods. newFixedThreadPool pairs n threads with an unbounded queue that can grow until memory runs out; newCachedThreadPool pairs a SynchronousQueue with unlimited threads and a 60-second timeout, so bursts can create thousands of threads; newSingleThreadExecutor runs tasks sequentially on one thread with an unbounded queue. For services, we construct ThreadPoolExecutor directly with a bounded queue, named threads and an explicit rejection policy, and with virtual threads we use newVirtualThreadPerTaskExecutor and express limits with semaphores or connection pools instead.

What to say in the interviewAbout 90 seconds aloud

Open with

All three return a ThreadPoolExecutor with particular settings, and each has a trap. newFixedThreadPool of n gives n threads and an unbounded LinkedBlockingQueue. Under overload nothing ever rejects, so the queue just grows, latency grows with it, and eventually we get an OutOfMemoryError, often long after the overload started. newCachedThreadPool has zero core threads, an unlimited maximum, a SynchronousQueue that holds nothing, and a 60-second idle timeout.

Then, if they want more

Every task that finds no idle thread gets a new one, so with slow tasks or a burst it can create thousands of platform threads and exhaust memory or the OS thread limit. newSingleThreadExecutor is one thread with an unbounded queue; it guarantees sequential order, but it has the same queue growth risk, and one stuck task stops everything behind it.

For a production service I'd construct ThreadPoolExecutor directly, or use Spring's ThreadPoolTaskExecutor, with a bounded queue such as an ArrayBlockingQueue of a few hundred, named threads from a thread factory so thread dumps make sense, and an explicit rejection policy, either AbortPolicy mapped to a 503, or CallerRunsPolicy for back pressure.

And on Java 21 and later, Executors.newVirtualThreadPerTaskExecutor starts a new virtual thread per task with no pooling, which is great for I/O-bound work, but then I'd limit concurrency to downstream systems explicitly with a Semaphore or the connection pool size.

About this answer

Last updated
12 November 2026
Versions it names
Java 19, Java 21
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What do Executors.newFixedThreadPool, newCachedThreadPool and newSingleThreadExecutor...": https://scrivio-interview-library.netlify.app/java/executors/8f1cb2a1fa/