StructuredTaskScope Exception Propagation Limits
0 reputation · 07 Mar 2022, 12:39 UTC
Subtask Exception Handling in JDK 21
Java's StructuredTaskScope provides a mechanism for managing groups of virtual threads (fibers) as a single unit of work. While the API allows for different policies regarding subtask failure, the interaction between nested scopes and exception propagation remains a point of design uncertainty.
When a subtask within a nested StructuredTaskScope throws an exception, the current implementation defines how the immediate parent scope reacts based on the chosen policy. However, the mechanism for bubbling these exceptions up through multiple layers of nested scopes without prematurely cancelling unrelated sibling tasks in higher-level scopes is not fully detailed.
Technical Constraints
- Requirement to maintain structured concurrency guarantees during failure.
- Avoidance of unintentional global shutdown when a localized subtask fails.
- Consistency between
ShutdownOnFailureand custom scope implementations.
Does the JVM provide a native mechanism to selectively propagate exceptions from a deeply nested fiber to a top-level scope without triggering a full shutdown of all intermediate scopes? How is the priority of exception handling resolved when multiple subtasks in different nested levels fail simultaneously?