Remark on the StructuredTaskScope API of Java 25

Alan Bateman alan.bateman at oracle.com
Thu Sep 25 14:01:09 UTC 2025


On 25/09/2025 06:38, forax at univ-mlv.fr wrote:
> :
>
> The problem, is that this check is a kind of weak, because you can write
>
> try(var sts = STS.open()) {
>     var subtask = sts.fork(callable);
>
>    // spurious STS are back !
>    Thread.ofVirtual().start(() -> IO.println(subtask.get())).join();
>
>     sts.join();
>   }
>

It's only interesting to call Subtask::get in the main task (after join) 
or in a custom Joiner's onComplete when the thread that executed the 
subtask completes. The specified seat belt is to avoid a mistake in the 
main task where code might attempt to get the result before joining. It 
would of course feasible to specify it be not allowed from other random 
threads that happen to get a reference to the subtask, but it would add 
overhead to cater for a very off-piste usage.

-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20250925/1b0454f1/attachment.htm>


More information about the loom-dev mailing list