J.VI · Java 25 practice question

A service creates an executor with Executors.newFixedThreadPool(4, factory). All four worker threads are currently busy executing long-running tasks when a fifth task is submitted. What happens to the fifth task?

Choose one answer
Check answer and explanation

Correct answer: The task waits in a shared unbounded queue until one of the four threads becomes available.

Explanation

A fixed thread pool operates with at most nThreads active threads off a shared unbounded queue, so additional tasks wait in that queue until a worker thread is free.

Common trap

Spawning a temporary fifth thread is tempting because cached thread pools grow on demand, whereas newFixedThreadPool caps active threads at nThreads. Throwing RejectedExecutionException is tempting if a developer assumes the pool uses a bounded queue, but newFixedThreadPool uses an unbounded queue.

Source: Java SE 25 API: Executors.newFixedThreadPool
Checked against the cited text on 2026-11-25.

Report an error in this question