<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<br>
Thanks for taking the time to write a mail on your experiences.<br>
<br>
On 15/10/2024 18:13, Winkelman, Kyle G wrote:<br>
<blockquote type="cite" cite="mid:PH7PR22MB53473F1277DF1FD94DAE8D8E83452@PH7PR22MB5347.namprd22.prod.outlook.com">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style>@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}@font-face
{font-family:"Times New Roman \(Body CS\)";
panose-1:2 11 6 4 2 2 2 2 2 4;}@font-face
{font-family:Menlo;
panose-1:2 11 6 9 3 8 4 2 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Aptos",sans-serif;
mso-ligatures:standardcontextual;}p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
font-size:11.0pt;
font-family:"Aptos",sans-serif;
mso-ligatures:standardcontextual;}span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Courier New";
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-size:11.0pt;}div.WordSection1
{page:WordSection1;}ol
{margin-bottom:0in;}ul
{margin-bottom:0in;}</style>
<div class="WordSection1">
<p class="MsoNormal"><span style="font-family:"Courier New"">Things that felt
strange or annoying:<o:p></o:p></span></p>
<ul style="margin-top:0in" type="disc">
<li class="MsoListParagraph" style="margin-left:0in;mso-list:l0 level1 lfo1"><span style="font-family:"Courier New"">When
subclassing StructuredTaskScope I always have to @Override
`join` and `joinUntil` to return my subclass type to
provide a fluent api.</span></li>
</ul>
</div>
</blockquote>
<br>
When doing a custom policy, and the subclass defines methods to make
available the outcome, then you do need to override the join method
with a covariant return type to make it possible for use sites to
make use of method invocation chaining. The override will likely
just do super.join() so shouldn't be too much of a burden, just a
bit annoying.<br>
<br>
There is an update to the API [1] in the EA builds and draft JEP
that moves the policy to a side object with a type parameter on STS
for the return from join. That takes the burden of subclassing off
the table.<br>
<br>
<br>
<br>
<blockquote type="cite" cite="mid:PH7PR22MB53473F1277DF1FD94DAE8D8E83452@PH7PR22MB5347.namprd22.prod.outlook.com">
<div class="WordSection1">
<ul style="margin-top:0in" type="disc">
<li class="MsoListParagraph" style="margin-left:0in;mso-list:l0 level1 lfo1"><span style="font-family:"Courier New"">When
subclassing StructuredTaskScope @Override `handleComplete`
I find myself wanting to write a switch expression on
Subtask#state(), but if I do, I always need to have a case
for UNAVAILABLE and throw IllegalStateException.<o:p></o:p></span></li>
<li class="MsoListParagraph" style="margin-left:0in;mso-list:l0 level1 lfo1"><span style="font-family:"Courier New"">Using
StructuredTaskScope (no subclassing) feels weird because
you must decide to use either the `<>` diamond
operator to allow any types or define a type T for
restricting subtasks (makes you wonder if you are using it
correctly). Whereas, both ShutdownOnFailure and
ShutdownOnSuccess just feel right to use.</span></li>
</ul>
</div>
</blockquote>
The code example you included had subtasks that yield results of
different types. There are cases where the tasks will all return
something of the same type. Using STS directly is the equivalent of
"no policy" so closer to the ES.invokeAll in that regard. The
default in the updated API is changed to work like ShutdownOnFailure
in the existing API because this is likely the 90% case.<br>
<br>
<br>
<blockquote type="cite" cite="mid:PH7PR22MB53473F1277DF1FD94DAE8D8E83452@PH7PR22MB5347.namprd22.prod.outlook.com">
<div class="WordSection1">
<ul style="margin-top:0in" type="disc">
<li class="MsoListParagraph" style="margin-left:0in;mso-list:l0 level1 lfo1"><span style="font-family:"Courier New""><o:p></o:p></span><br>
</li>
<li class="MsoListParagraph" style="margin-left:0in;mso-list:l0 level1 lfo1"><span style="font-family:"Courier New"">In IntelliJ
the Javadoc of StructuredTaskScope doesn’t seem to
properly format and makes it very difficult to read
(probably an issue with IntelliJ).</span></li>
</ul>
</div>
</blockquote>
I don't know what this except to note that the API docs have several
code snippets, maybe the IDE version you are using can't handle
this.<br>
<br>
<br>
<blockquote type="cite" cite="mid:PH7PR22MB53473F1277DF1FD94DAE8D8E83452@PH7PR22MB5347.namprd22.prod.outlook.com">
<div class="WordSection1"><br>
<ul style="margin-top:0in" type="disc">
<li class="MsoListParagraph" style="margin-left:0in;mso-list:l0 level1 lfo1"><span style="font-family:"Courier New"">Blocking IO is
not interruptible and this can cause confusion when the
scope won’t close in a timely manner even though something
may have already thrown an exception (probably falls under
the Non-Goal of thread cancellation mechanism). e.g. 2
calls to fork one reading a short file and the other
reading an long file, short one fails, if I don’t do
something to close the long file stream I will read the
whole thing (making ShutdownOnFailure not really live up
to its name).</span></li>
</ul>
</div>
</blockquote>
<br>
Our expectation is that STS will be mostly used for fan out to
network services. The blocking Socket methods were re-specified in
JDK 19 so that interrupt closes the Socket, similar to interruptible
channels, when used in the virtual threads. SocketChannel is an
interruptible channel so okay there, even when configured blocking.<br>
<br>
Your example launches sub-Processes which doesn't have a good story
for cancellation/interrupt. I hope in time that it will get
attention.<br>
<br>
-Alan<br>
<br>
<br>
[1]
<a class="moz-txt-link-freetext" href="https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/StructuredTaskScope.html">https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/StructuredTaskScope.html</a><br>
</body>
</html>