<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
You know what, you are right. I double checked the interface that Spring Integration was expecting and it only needs a Executor, not an ExecutorService. I got mixed up and started down the wrong rabbit hole! So you are correct, I don't need to manage the lifecycle
 and it is a much simpler problem with maybe 10 lines of code.</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> robert engels <rengels@ix.netcom.com><br>
<b>Sent:</b> May 13, 2024 3:07 PM<br>
<b>To:</b> Colin Redmond <Colin.Redmond@outlook.com><br>
<b>Cc:</b> Attila Kelemen <attila.kelemen85@gmail.com>; masoud parvari <masoud.parvari@gmail.com>; loom-dev@openjdk.org <loom-dev@openjdk.org><br>
<b>Subject:</b> Re: Resource Constrained Thread Per Task Executor</font>
<div> </div>
</div>
<div class="" style="word-wrap:break-word; line-break:after-white-space">If you use an Executor the entire code should be less than 10 lines -  then you don’t need to manage the lifecycle, etc. - all it is is a semaphore and the spawning of a new virtual thread
 when then the semaphore is granted.
<div class=""><br class="">
</div>
<div class="">If you need to return Futures for cancellation / results it is a bit more complicated but not much.<br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On May 13, 2024, at 4:34 PM, Colin Redmond <<a href="mailto:Colin.Redmond@outlook.com" class="">Colin.Redmond@outlook.com</a>> wrote:</div>
<br class="x_Apple-interchange-newline">
<div class="">
<div class="x_elementToProof" style="font-size:12pt; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif">
Thanks for the idea, the<span class="x_Apple-converted-space"> </span><code class="">AbstractExecutorService</code>​ would be a great starting place, and that means I need to implement all the shutdown logic. Which is manageable, but tricky. I guess the moral
 of the story is there is no easy way out of the box to implement constrained resources with new thread per task executors. I will have to write some code and reimplement some things to get what I want.</div>
<div class="x_elementToProof" style="font-size:12pt; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif">
<br class="">
<br class="">
But maybe someone can answer me the question: is it safe to keep a virtual thread for an extended period of time? Maybe I can live with my ThreadPoolExecutor solution if it is safe. For my use case it works, but it isn't ideal.</div>
<div class="x_elementToProof" style="font-size:12pt; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif">
<br class="">
</div>
<div class="x_elementToProof" style="font-size:12pt; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif">
Thanks all for the feedback!</div>
<div id="x_appendonsend" class="" style="font-family:Helvetica; font-size:16px; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
</div>
<hr tabindex="-1" class="" style="font-family:Helvetica; font-size:16px; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; display:inline-block; width:672.265625px">
<span class="" style="font-family:Helvetica; font-size:16px; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; float:none; display:inline!important"></span>
<div id="x_divRplyFwdMsg" dir="ltr" class="" style="font-family:Helvetica; font-size:16px; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<font face="Calibri, sans-serif" class="" style="font-size:11pt"><b class="">From:</b><span class="x_Apple-converted-space"> </span>Attila Kelemen <<a href="mailto:attila.kelemen85@gmail.com" class="">attila.kelemen85@gmail.com</a>><br class="">
<b class="">Sent:</b><span class="x_Apple-converted-space"> </span>May 13, 2024 2:22 PM<br class="">
<b class="">To:</b><span class="x_Apple-converted-space"> </span>Colin Redmond <<a href="mailto:Colin.Redmond@outlook.com" class="">Colin.Redmond@outlook.com</a>><br class="">
<b class="">Cc:</b><span class="x_Apple-converted-space"> </span>masoud parvari <<a href="mailto:masoud.parvari@gmail.com" class="">masoud.parvari@gmail.com</a>>; Robert Engels <<a href="mailto:rengels@ix.netcom.com" class="">rengels@ix.netcom.com</a>>;<span class="x_Apple-converted-space"> </span><a href="mailto:loom-dev@openjdk.org" class="">loom-dev@openjdk.org</a><span class="x_Apple-converted-space"> </span><<a href="mailto:loom-dev@openjdk.org" class="">loom-dev@openjdk.org</a>><br class="">
<b class="">Subject:</b><span class="x_Apple-converted-space"> </span>Re: Resource Constrained Thread Per Task Executor</font>
<div class=""> </div>
</div>
<div class="" style="font-family:Helvetica; font-size:16px; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<div dir="ltr" class="">
<div class="">You can't really acquire everything at once, because you might get so many tasks that you could never fulfil such a request. That said, `invokeAll` can simply be done by submitting all tasks one after another. Implementing `invokeAny` well might
 be trickier, but I have never seen anyone ever using it, so I wouldn't worry too much about it. But you can check `AbstractExecutorService` for both. In fact, you can actually use it as a base class to provide implementation for the invoke many methods.</div>
<br class="">
<div class="x_x_gmail_quote">
<div dir="ltr" class="x_x_gmail_attr">Colin Redmond <<a href="mailto:Colin.Redmond@outlook.com" class="">Colin.Redmond@outlook.com</a>> ezt írta (időpont: 2024. máj. 13., H, 23:05):<br class="">
</div>
<blockquote class="x_x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div class="x_x_msg1736266011587329725">
<div dir="ltr" class="">
<div class="" style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt">I may be overthink this. I was hoping for an easy way to extend the ThreadPerTaskExecutor like the ThreadPoolExecutior is extensible. But I Agree in this case that it should wrap
 another executor as getting threading correct is hard! For the Executor Service, Execute and Submit would he easy to manage, as it is a single task so easy to get a acquire a single resource from a semaphore. But I will need to be more careful around invokeAll
 and invokeAny, as I may need to acquire more permits than are available or one invoke all may block another invoke from executing in parallel. So maybe I can submit them one at time, or just go ahead and get the number of permits at once.</div>
<div class="" style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt"><br class="">
</div>
<div class="" style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt">It is good to know that i dont need to use any jdk.internal classes. I saw both ThreadPerTaskExecutor  and ThreadPoolExecutor using ThreadContainer and i wasn't sure if it was some
 special class to manage threads. I can implement something without this.</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</body>
</html>