<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<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);">
If it is safe to keep virtual threads and pool them, there is still a net benefit to pooling virtual threads. I agree a major benefits of virtual threads is that they are cheap to create, so there is no
<b>need </b>to pool them. But the memory and performance increase even pooling is no small matter.</div>
<div class="elementToProof" style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
In my case I have 500 platform threads I am limited because my container is small and they start to use a significant portion of the memory. I switch them for 1000 virtual threads, this saves me ~ 500 mb of RAM (maybe less i didn't do the math). Between less
 need for context switching and more memory for garbage, I am still seeing a 20 - 30% improvements. Which even with pooled virtual threads is a big improvement.</div>
<div class="elementToProof" style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Firstly I was hoping there was an existing solution, I googled it a while but couldn't find any specific open source packages if anyone knows any let me know, I would prefer to import something. If not I may continue my journey of writing a new ExecutorService
 for my use case. <br>
<br>
</div>
<div id="appendonsend"></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr style="display: inline-block; width: 98%;">
<div id="divRplyFwdMsg" dir="ltr"><span style="font-family: Calibri, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);"><b>From:</b> Attila Kelemen <attila.kelemen85@gmail.com><br>
<b>Sent:</b> May 13, 2024 2:41 PM<br>
<b>To:</b> Colin Redmond <Colin.Redmond@outlook.com><br>
<b>Cc:</b> masoud parvari <masoud.parvari@gmail.com>; Robert Engels <rengels@ix.netcom.com>; loom-dev@openjdk.org <loom-dev@openjdk.org><br>
<b>Subject:</b> Re: Resource Constrained Thread Per Task Executor</span>
<div> </div>
</div>
<div style="direction: ltr;">If you are wrapping another `ExecutorService`, then you don't really need to have anything special for `shutdown` and such. You just have to delegate those calls.</div>
<div style="direction: ltr;"><br>
</div>
<div style="direction: ltr;">As for "is it safe to keep a virtual thread for an extended period of time": Yes, it is safe, but pooling VT defeats its purpose.</div>
<div style="direction: ltr;"><br>
</div>
<div style="direction: ltr;">Colin Redmond <<a href="mailto:Colin.Redmond@outlook.com" id="OWA4f27cd95-9e50-52c8-c74e-72eb56df10e2" class="OWAAutoLink">Colin.Redmond@outlook.com</a>> ezt írta (időpont: 2024. máj. 13., H, 23:34):</div>
<blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left: 1px solid rgb(204, 204, 204);">
<div style="direction: ltr; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks for the idea, the <code>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 style="direction: ltr; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
<br>
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 style="direction: ltr; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="direction: ltr; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks all for the feedback!</div>
</blockquote>
</body>
</html>