single thread executor

Mushtaq Ahmed mushtaq.a at gmail.com
Mon Jul 18 09:18:24 UTC 2022


Thanks for the quick clarification!

Good to know that is on the roadmap.

I intend to make use of this for building a DSL where a user can
a) update the mutable variables without having to think about concurrency
(because of single carrier thread)
b) freely use blocking (because of virtual threads within that carrier
thread)


On Mon, Jul 18, 2022 at 2:35 PM Ron Pressler <ron.pressler at oracle.com>
wrote:

> 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> 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/e82e9cf9/attachment.htm>


More information about the loom-dev mailing list