Executors.newVirtualThreadPerTaskScheduledExecutor() ?
Formula Salt
formulasalt410 at gmail.com
Tue Aug 1 05:57:15 UTC 2023
Hi,
I am trying to use virtual threads together with the
ScheduledExecutorService but I am uncertain what is the best way to do so.
To use the ExecutorService with virtual threads we would use
Executors.newVirtualThreadPerTaskExecutor() but there seems to be no
equivalent method for the ScheduledExecutorService.
Executors.newScheduledThreadPool(int, ThreadFactory) would require pooling
virtual threads which I believe is considered bad practice.
Executors.newSingleThreadScheduledExecutor(ThreadFactory) only allows for a
single thread so tasks must execute sequentially.
The best way I've found so far is in this StackOverflow answer (
https://stackoverflow.com/a/76599122) which suggests using both a
single-threaded ScheduledExecutorService and
Executors.newVirtualThreadPerTaskExecutor(). This works but perhaps the
Executors API should directly support this
via Executors.newVirtualThreadPerTaskScheduledExecutor() ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230801/8de955db/attachment-0001.htm>
More information about the loom-dev
mailing list