<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
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="Signature">
<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="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> loom-dev <loom-dev-retn@openjdk.org> on behalf of Alan Bateman <alan.bateman@oracle.com><br>
<b>Sent:</b> Sunday, 24 August 2025 08:19<br>
<b>To:</b> David Alayachew <davidalayachew@gmail.com><br>
<b>Cc:</b> loom-dev <loom-dev@openjdk.org><br>
<b>Subject:</b> Re: When should I use onFork?</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText"><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>
</body>
</html>