New candidate JEP: 505: Structured Concurrency (Fifth Preview)
Glavo
zjx001202 at gmail.com
Mon Apr 14 19:34:57 UTC 2025
Hi Mark,
I noticed an error and a formatting issue in the document:
1. Missing closing bracket before the `throws`:
<T> List<T> runConcurrently(Collection<Callable<T>> tasks throws
InterruptedException {
> try (var scope = StructuredTaskScope.open(Joiner.<T>allSuccessfulOrThrow())) {
> tasks.forEach(scope::fork);
> return scope.join().map(Subtask::get).toList();
> }
> }
>
>
2. There is extra space after the `extends` in `Subtask<? extends T>`:
class CollectingJoiner<T> implements Joiner<T, Stream<T>> {
>
> private final Queue<T> results = new ConcurrentLinkedQueue<>();
>
> public boolean onComplete(Subtask<? extends T> subtask) {
> if (subtask.state() == Subtask.State.SUCCESS) {
> results.add(subtask.get());
> }
> return false;
> }
>
> public Stream<T> result() {
> return results.stream();
> }
>
> }
>
>
Glavo
On Tue, Apr 15, 2025 at 3:17 AM Mark Reinhold <mark.reinhold at oracle.com>
wrote:
> https://openjdk.org/jeps/505
>
> Summary: Simplify concurrent programming by introducing an API for
> structured concurrency. Structured concurrency treats groups of
> related tasks running in different threads as single units of work,
> thereby streamlining error handling and cancellation, improving
> reliability, and enhancing observability. This is a preview API.
>
> - Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20250415/466d8a8a/attachment.htm>
More information about the jdk-dev
mailing list