<div dir="ltr">Yes, that is what I intended to say. <div>I apologize for any confusion. Is there a plan to incorporate this feature in the future?<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jun 17, 2023 at 11:04 AM Holo The Sage Wolf <<a href="mailto:holo3146@gmail.com">holo3146@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>It doesn't seem to me that you want to pool virtual threads.</div><div dir="auto"><br></div><div dir="auto">The thread-per-core architecture seems to benefit from using VM threads directly, and wrapping it with a virtual thread will give you the cost of the abstraction without the benefits.</div><div dir="auto"><br></div><div dir="auto">If you want the benefits of the programming model of virtual threads (e.g. not needing to use reactive-like programming) you need to guarantee that your virtual threads run on a given pool of VM threads, something like e.g.</div><div dir="auto"><br></div><div dir="auto">private static ThreadLocal<ThreadFactory> virtualFactory = new ThreadLocal<>();</div><div dir="auto"><br></div><div dir="auto">public static void fork(Runnable r) {</div><div dir="auto"> // Run using virtualFactory.get()...</div><div dir="auto">}</div><div dir="auto"><br></div><div dir="auto">public static void main(string[] args) {</div><div dir="auto"> for (/* core in cores */) {</div><div dir="auto"> ThreadPerCoreExecuter(core, () -> {</div><div dir="auto"> virtualFactory.set(Thread </div><div dir="auto"> .ofVirtual()</div><div dir="auto"> .factory(currentThread()));</div><div dir="auto"> // The thread logic, while using `fork`</div><div dir="auto"> });</div><div dir="auto"> }</div><div dir="auto">}</div><div dir="auto"><br></div><div dir="auto">as far as I can remember, this is currently not possible<br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Sat, Jun 17, 2023, 07:58 Andrii Lomakin <<a href="mailto:lomakin.andrey@gmail.com" target="_blank">lomakin.andrey@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Attila. <div>Cool! I want to implement an architecture that, for example, ScillaDB uses. DB instances are sharded not by per server node but by CPU core node.</div><div>That allows us to avoid the usage of memory fences during the usage of locks (additionally implemented, of course) and use a wider set of data structures (because of the usage of cooperative concurrency). <br></div><div>There is a very cool presentation about such architecture in Hydar (if you are curious to check it) - <a href="https://www.youtube.com/watch?v=JPTt1ny67x4" rel="noreferrer" target="_blank">https://www.youtube.com/watch?v=JPTt1ny67x4</a></div><div><br><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 16, 2023 at 11:34 PM Attila Kelemen <<a href="mailto:attila.kelemen85@gmail.com" rel="noreferrer" target="_blank">attila.kelemen85@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Sorry, wrong copy paste, instead of
`Executors.newVirtualThreadPerTaskExecutor()` I meant `Thread.ofVirtual().factory()` of course.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Attila Kelemen <<a href="mailto:attila.kelemen85@gmail.com" rel="noreferrer" target="_blank">attila.kelemen85@gmail.com</a>> ezt írta (időpont: 2023. jún. 16., P, 23:30):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">`ThreadPoolExecutor` already allows a custom `ThreadFactory` to which you can pass `Executors.newVirtualThreadPerTaskExecutor()`. However, why would you create a new server using loom on thread/core when you want to rely on virtual threads? That just means that you are pooling virtual threads which seems to be pointless (basically you are creating a queue in order to put them in another). If you want to limit the number of concurrent access, then you can do that with a semaphore.<br><div><br></div><div>Attila</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Andrii Lomakin <<a href="mailto:lomakin.andrey@gmail.com" rel="noreferrer" target="_blank">lomakin.andrey@gmail.com</a>> ezt írta (időpont: 2023. jún. 16., P, 7:59):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Good day devs!<div> I am considering the creation of a database server that is working on thread-per-core architecture. So I have a question: do you have plans to implement the possibility of using virtual threads executor on the base of a passed executor? </div><div><br></div><div>P.S. I am aware of problems with synchronization inside JDK classes, libraries, and pinned threads.<br><div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Best regards,<br>Andrii Lomakin.<br><br></div></div></div></div></div></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Best regards,<br>Andrii Lomakin.<br><br></div></div></div></div>
</blockquote></div></div></div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Best regards,<br>Andrii Lomakin.<br><br></div></div></div></div>