How to specify scheduler for virtual threads

Alan Bateman Alan.Bateman at oracle.com
Tue Nov 19 22:49:25 UTC 2019


On 19/11/2019 21:43, Arkadiusz Gasiński wrote:
> Hi,
>
> Quick question... How do I specify scheduler to be used to schedule virtual
> threads after recent changes? The Thread.newLightWeightThread method that
> was removed, had an overloaded version that allowed to specify scheduler,
> but that's not true for Thread.newThread method. What am I missing? Or is
> that functionality not yet ready in the new API?
>
Still work in progress but you should find what you need in 
Thread.Builder. There are several examples in the javadoc, this one is 
probably close to what you want:

Executor scheduler = ...
ThreadFactory factory = 
Thread.builder().virtual().scheduler(scheduler).factory();

-Alan


More information about the loom-dev mailing list