Java / Java 21 Virtual Threads Interview questions
What is structured concurrency?
Structured concurrency is a programming model where a group of related concurrent subtasks is treated as a single unit of work that shares a lifetime, entry point, and exit point with its parent task.
In Java 21 it's delivered through StructuredTaskScope as a preview API (JEP 453, requiring --enable-preview), letting you fork subtasks as virtual threads inside a scope and join them together.
The benefit is that errors, cancellation, and timeouts in one subtask can automatically propagate to its siblings, preventing the classic problem of an orphaned background thread that outlives the logic that spawned it.
More Related questions...