Q69: What is Structured Concurrency (Java 21 / Preview) and how does StructuredTaskScope work?

Structured Concurrency treats concurrent tasks running in separate threads as a single unit of work. Using StructuredTaskScope, child threads spawned to process sub-tasks share the lifespan and execution scope of their parent task, ensuring clean cancellation, error propagation, and observability.

Key Takeaways
  • Treats concurrent sub-tasks as a unified structured scope.
  • Ensures child thread failures automatically cancel sibling tasks.
Knowledge Check

What happens in StructuredTaskScope.ShutdownOnFailure when one child sub-task throws an exception?