JEP 505, the Structured Concurrency Fifth Preview, has achieved Targeted status in JDK 25, serving to simplify parallel task management for developers, especially with virtual threads.
The latest preview refines the API introduced in preceding iterations and enables developers to open a scope using static factory methods like StructuredTaskScope.open().
Structured concurrency focuses on confining subtask lifetimes, implementing reliable cancellation, and enhancing observability through structured thread hierarchies.
The API revolves around the java.util.concurrent.StructuredTaskScope class, facilitating the management of concurrent subtasks within a specified scope.
A coding example illustrates the usage pattern, where tasks are forked, executed concurrently, and then joined within the scope, ensuring completion or cancellation before leaving the block.
A notable improvement in the fifth preview includes factory method usage for scope creation, enhancing readability and accommodating future API evolution without compatibility issues.
Custom policies can be supplied via factory methods like StructuredTaskScope.open(Joiner) to define specific task completion behaviors.
The Joiner interface offers flexibility for implementing custom completion policies, ensuring proper handling of subtask operations within the scope.
Each Joiner instance should be exclusively used within a single StructuredTaskScope and not across different scopes or after closure.
Developers are encouraged to experiment with the Structured Concurrency Fifth Preview in JDK 25 to provide feedback for further maturing the API.