StructuredTaskScope
Fork and join subtasks.
Meet StructuredTaskScope
StructuredTaskScope is the core API of structured concurrency. You open a scope, fork subtasks, join to wait for them, then read their results.
It is a preview feature, so compile and run with --enable-preview.
The Basic Lifecycle
Every use follows the same four-step rhythm:
- Open the scope in a try-with-resources block
forkone or more subtasks, each returning aSubtaskhandlejointo wait for completion- Read each subtask's result via
get()