J.VI · Java 25 practice question
Which of the following accurately describes the difference between using `Executors.newFixedThreadPool(N)` and `Executors.newVirtualThreadPerTaskExecutor()` when submitting a task using `submit()`? Assume the tasks run for a short duration.
Check answer and explanation
Correct answer: `newFixedThreadPool(N)` creates a pool of N platform threads that are reused, while `newVirtualThreadPerTaskExecutor()` creates a new virtual thread for every submitted task, offering near-unbounded concurrency capacity limited only by memory.
Explanation
`Executors.newFixedThreadPool(N)` manages a finite pool of OS/Platform threads, recycling them among tasks. `Executors.newVirtualThreadPerTaskExecutor()` maps each task to a dedicated lightweight virtual thread. Virtual threads are designed to allow massive concurrency by switching context cheaply, effectively offering a per-task execution model without the overhead of creating a new platform thread for every task.
Common trap
Option A incorrectly describes the nature of the virtual thread executor; it is not a traditional "shared pool" in the way a fixed thread pool is, but rather a means of dispatching tasks to dynamically created threads. Option B correctly contrasts the resource limits (fixed vs. near-unbounded lightweight threads).
Source: Java SE 25 JEPs/Docs regarding Virtual Threads and Executors (Specific Javadoc linkage for `Executors` might point to the core concurrency package documentation.) https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/Executors.
Checked against the cited text on 2026-11-27.