single thread executor

Ron Pressler ron.pressler at oracle.com
Mon Jul 18 09:05:40 UTC 2022


Hi.

Custom schedulers were not delivered as part of JEP 425, as they are not yet ready for release.
We intend to add that feature at a later date. Until then, only the default scheduler can schedule virtual threads.

— Ron

On 18 Jul 2022, at 08:50, Mushtaq Ahmed <mushtaq.a at gmail.com<mailto:mushtaq.a at gmail.com>> wrote:

Google search for a similar use case led me to this discussion.

It seems that API has changed in the latest builds.

What is the current way to achieve the following?

Thread.builder().virtual(Executors.newSingleThreadExecutor()).factory()

Thanks,
Mushtaq

-----------------------------------------------------
Reference to the original thread (in case this email shows up outside the original thread, not sure how mailman works):

Remember, you want multiple virtual threads, but use only on platform
thread to schedule them. So you need to pass the single-thread executor
as the virtual thread scheduler:

    ThreadFactory tf = Thread.builder().virtual(Executors.newSingleThreadExecutor()).factory(); And then you can use the thread factory directly to create virtual threads, or use it like so:     ExecutorService e = Executors.newUnboundedExecutor(tf); - Ron


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20220718/e2aa8d31/attachment-0001.htm>


More information about the loom-dev mailing list