<div dir="auto"><div dir="auto">Thanks for the context Alan and Viktor. I guess since Virtual Threads kick off tasks so fast (due to their throughput), I never had a chance to observe this behaviour.<div dir="auto"><br></div><div dir="auto">But I think I get it -- once the scope closes, all future calls to fork() fail, so onFork() simply doesn't get called.</div><div dir="auto"><br></div><div dir="auto">That is a very important detail though. Hope you don't mind, but let me change subject to make sure I understand this behaviour.</div><div dir="auto"><br></div><div dir="auto">For example, let's say I use the anySuccessfulOrThrow Joiner. Then, theoretically speaking, if I have enough tasks such that by the time the scope closes, I am still feeding tasks into fork(), then my scope will fail? Am I understanding that correctly?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Aug 24, 2025, 7:21 AM Viktor Klang <<a href="mailto:viktor.klang@oracle.com" rel="noreferrer noreferrer noreferrer" target="_blank">viktor.klang@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
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.</div>
<div id="m_-1532916408701208876m_-1034765039309818972m_7812020998199201726m_-8959468810093654737Signature">
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Cheers,<br>
√</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<b><br>
</b></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<b>Viktor Klang</b></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Software Architect, Java Platform Group<br>
Oracle</div>
</div>
<div id="m_-1532916408701208876m_-1034765039309818972m_7812020998199201726m_-8959468810093654737appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="m_-1532916408701208876m_-1034765039309818972m_7812020998199201726m_-8959468810093654737divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> loom-dev <<a href="mailto:loom-dev-retn@openjdk.org" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">loom-dev-retn@openjdk.org</a>> on behalf of Alan Bateman <<a href="mailto:alan.bateman@oracle.com" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">alan.bateman@oracle.com</a>><br>
<b>Sent:</b> Sunday, 24 August 2025 08:19<br>
<b>To:</b> David Alayachew <<a href="mailto:davidalayachew@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">davidalayachew@gmail.com</a>><br>
<b>Cc:</b> loom-dev <<a href="mailto:loom-dev@openjdk.org" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">loom-dev@openjdk.org</a>><br>
<b>Subject:</b> Re: When should I use onFork?</font>
<div> </div>
</div>
<div><font size="2"><span style="font-size:11pt">
<div><br>
<br>
On 23/08/2025 20:27, David Alayachew wrote:<br>
> Woah, very good to know. And thus, even when the scope is closed, <br>
> onFork will still be called is what you are saying?<br>
><br>
> Thanks for this. Very useful.<br>
><br>
No, fork is specified to throw IllegalStateException if closed. My <br>
comment is pointing out that if you cancel the scope then the result <br>
from any subtasks that are still executing does not contribute to the <br>
outcome. Once you cancel then onComplete for these "still running (and <br>
interrupted)" subtasks won't be called. To put it another way, if the <br>
outcome from join is something derived from all subtasks that were <br>
forked then you'll need to implement onFork. It may be more common that <br>
the outcome is derived from the result/exception from a subset of the <br>
subtasks, in which case it will be the onComplete method that you implement.<br>
<br>
-Alan<br>
</div>
</span></font></div>
</div>

</blockquote></div></div>