ExecutorService.awaitTermination and virtual threads
Kasper Nielsen
kasperni at gmail.com
Mon Dec 9 18:34:47 UTC 2019
> Once there are a few more pieces in place then it should be possible to
> do the following with the prototype:
>
> try (ExecutorService scheduler = Executors.newFixedThreadPool(1)) {
> ThreadFactory factory = Thread.builder()
> .virtual()
> .scheduler(scheduler)
> .name("virtual-thread-", 1)
> .factory();
> });
> }
> }
>
Would it make sense to have this instead
ThreadFactory.virtual()
ThreadFactory.virtual(Executor scheduler)
I do think .virtual(scheduler) reads a bit clearer than
.virtual().scheduler(scheduler)
And you effectively convey that you can only schedule virtual threads.
If you at some point add new thread types that need a scheduler you
can always use the same trick.
/Kasper
More information about the loom-dev
mailing list