J.VI · Java 25 practice question

While an executor created by Executors.newFixedThreadPool(4, factory) is still running (before shutdown), one of its worker threads terminates due to an uncaught failure during task execution. What happens to the pool's capacity for subsequent tasks?

Choose one answer
Check answer and explanation

Correct answer: A new thread is created to replace the terminated one if needed for subsequent tasks.

Explanation

When a worker thread in a fixed thread pool dies from a failure prior to shutdown, the pool replaces it with a new thread if needed to run later tasks.

Common trap

Permanently shrinking the pool to three threads is tempting if a developer assumes fixed thread pools pre-create threads once and never recreate them, but the pool automatically replaces failed workers. Shutting down the entire executor is tempting if someone expects fail-fast pool termination on any task exception, whereas newFixedThreadPool continues serving subsequent tasks.

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

Report an error in this question