J.VI · Java 25 practice question

A developer is writing a high-throughput service that performs many short, CPU-bound computations, but occasionally needs to block waiting for a result from a low-latency local cache lookup. They are considering using Java's Virtual Threads. Which scenario is the **worst** use case for leveraging Virtual Threads' non-blocking nature (i.e., when should they avoid relying on automatic blocking)?

Choose one answer
Check answer and explanation

Correct answer: When the core business logic is computationally intensive and does not involve any blocking waits.

Explanation

Virtual Threads are designed to make blocking operations (like I/O waits) cheap, allowing many threads to run concurrently without the overhead of platform threads. If the code is purely CPU-bound (Option D), the benefit of virtual threads over platform threads is minimal, and the focus should remain on efficient CPU scheduling or perhaps structuring logic to minimize contention, not solely relying on virtual threads for blocking management. Short blocks (A) and I/O waits (C) are where they shine.

Common trap

Students often assume that virtual threads solve all concurrency problems. Option A might be tempting, but the primary benefit is hiding latency during *blocking* I/O, not optimizing extremely fast, contention-prone CPU locking.

Source: Virtual Threads - Java Language Specification (JEP 444) https://openjdk.org/jeps/444
Checked against the cited text on 2026-11-27.

Report an error in this question