- Loading...
...
The main benefit of structured concurrency is abstraction. A caller of a method that is invoked to do a task should not care if the method decomposes the task and schedules a million fibers. When the method completes, any fibers scheduled by the method should have terminated.
...
In Project Loom, a prototype API has been was developed called FiberScope that is a scope in which fibers are scheduled. . That prototype is currently paused as Project Loom transitions to using java.lang.Thread as the API for fibers/lightweight threads. The prototype will come back, probably in a different form, once the project is over the transition.
Here is a basic example using that prototype:
| Code Block | ||
|---|---|---|
| ||
try (var scope = FiberScope.open()) {
var fiber1 = scope.schedule(task);
var fiber2 = scope.schedule(task);
} |
...