Remark on the StructuredTaskScope API of Java 25
forax at univ-mlv.fr
forax at univ-mlv.fr
Sun Oct 19 10:54:14 UTC 2025
> From: "Alan Bateman" <alan.bateman at oracle.com>
> To: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "loom-dev" <loom-dev at openjdk.java.net>
> Sent: Sunday, October 19, 2025 12:32:09 PM
> Subject: Re: Remark on the StructuredTaskScope API of Java 25
> On 25/09/2025 21:46, [ mailto:forax at univ-mlv.fr | forax at univ-mlv.fr ] wrote:
>>> From: "Alan Bateman" [ mailto:alan.bateman at oracle.com |
>>> <alan.bateman at oracle.com> ]
>>> To: "Remi Forax" [ mailto:forax at univ-mlv.fr | <forax at univ-mlv.fr> ] , "loom-dev"
>>> [ mailto:loom-dev at openjdk.java.net | <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.
> I don't think this is right argument to change it to return List. However,
> another angle is that users might assume the stream is lazily populated and
> that results can be consumed before join completes. For this Joiner, join is
> meant to wait until all subtasks complete or any subtask fails. So while
> returning a Stream is much more flexible, it may indeed be better to return a
> List<T>.
I agree, this argument is a better argument.
But I still disagree that a Stream is more flexible than a List, a stream is an abstraction over a computation, it can be an infinite loop.
> -Alan
regards,
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20251019/faf63ba8/attachment-0001.htm>
More information about the loom-dev
mailing list