When should I use onFork?
Viktor Klang
viktor.klang at oracle.com
Sun Aug 24 11:21:29 UTC 2025
Not sure this applies to your specific situation, David, but for the other readers of this conversation I also want to raise the point that implementing a Joiner must be done in a thread-safe manner.
Cheers,
√
Viktor Klang
Software Architect, Java Platform Group
Oracle
________________________________
From: loom-dev <loom-dev-retn at openjdk.org> on behalf of Alan Bateman <alan.bateman at oracle.com>
Sent: Sunday, 24 August 2025 08:19
To: David Alayachew <davidalayachew at gmail.com>
Cc: loom-dev <loom-dev at openjdk.org>
Subject: Re: When should I use onFork?
On 23/08/2025 20:27, David Alayachew wrote:
> Woah, very good to know. And thus, even when the scope is closed,
> onFork will still be called is what you are saying?
>
> Thanks for this. Very useful.
>
No, fork is specified to throw IllegalStateException if closed. My
comment is pointing out that if you cancel the scope then the result
from any subtasks that are still executing does not contribute to the
outcome. Once you cancel then onComplete for these "still running (and
interrupted)" subtasks won't be called. To put it another way, if the
outcome from join is something derived from all subtasks that were
forked then you'll need to implement onFork. It may be more common that
the outcome is derived from the result/exception from a subset of the
subtasks, in which case it will be the onComplete method that you implement.
-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20250824/416c255a/attachment-0001.htm>
More information about the loom-dev
mailing list