Remark on the StructuredTaskScope API of Java 25
forax at univ-mlv.fr
forax at univ-mlv.fr
Thu Sep 25 20:46:30 UTC 2025
> From: "Alan Bateman" <alan.bateman at oracle.com>
> To: "Remi Forax" <forax at univ-mlv.fr>, "loom-dev" <loom-dev at openjdk.java.net>
> Sent: Thursday, September 25, 2025 3:50:16 PM
> Subject: Re: Remark on the StructuredTaskScope API of Java 25
> On 24/09/2025 16:37, Remi Forax wrote:
>> :
>> - allSuccessfulOrThrow() should return a Joiner<T, List<Subtask<T>>>, so the
>> result is a List and not a stream.
>> In terms of implementation, in result(), the code should be
>> return Collections.unmodifiableList(subtasks);
> Can you say more on this? Right now, preferring a stream works well. For a
> Joiner returned by allSuccessfulOrThrow it makes it easy to use
> join().map(Subtask::get) or other mapping function. Add .toList() to get a
> list.
A collection is more powerful than a Stream, you can always do more with a List than with a Stream
(like indexed access).
Yes, you can always call toList() on a stream, but you are asking to duplicate all the elements,
here stream.toList() is semantically equivalent to a call to List.copyOf(), so it's slow if you have quite a lot of elements.
So yes, it might be convenient for some use cases to return a stream than to call .stream() on the returned List,
but you are trading convenience for performance.
> When using a Joiner created with allUntil then you may have to use a collector
> that partitions the subtasks into those that were successfull and those that
> didn't complete successfully.
Yes, it can be more convenient for some use cases.
I'm not advocating that, but you can also do both, you can add a bunch of default methods like all(), stream(), iterator(), etc on the interface Jiner (see my other mail) but it also make the API bigger than it should be.
> -Alan
regards,
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20250925/a1ac4b69/attachment.htm>
More information about the loom-dev
mailing list