Custom Schedulers: Customize current time and timed waits
Quinn Klassen
quinn.klassen at temporal.io
Sun Jun 22 22:24:06 UTC 2025
Yep! I understand nothing has been decided yet. I just saw
https://github.com/openjdk/loom/blob/fibers/loom-docs/CustomSchedulers.md/
so I built the JVM over the weekend and was experimenting with it since I
think the library I maintain has a interesting use case for schedulers.
For timed operations ideally I would like the virtual thread to request the
scheduler it wants to do a timed operation and the scheduler decides how to
accomplish this. That may be too high level an interface to add since it
looks like more libraries use `java.util.concurrent.locks.LockSupport`. This
is my first time looking at the implementation of some of these low level
calls, but maybe it would be more realistic to allow a pluggable time
source and interception of these parking utilities.
On Sun, Jun 22, 2025 at 12:10 PM Alan Bateman <alan.bateman at oracle.com>
wrote:
>
>
> On 22/06/2025 18:07, Quinn Klassen wrote:
> > :
> >
> > Experimenting with the custom schedules it seems like we now could
> > control how threads are scheduled and executed (amazing!), but we
> > still can't control the current time or how threads sleep. For example
> > if a thread with a custom scheduler calls `Thread.sleep` there is no
> > way for the scheduler to control when that will return, even if the
> > scheduler tries to unpark the thread the `for` loop in
> > `VirtualThread.sleepNanos` will keep parking it. In other
> > languages that support a custom scheduler for tasks like Python,
> > Javascript, Dotnet, Rust or Ruby this sort of behaviour is customizable.
> >
> > Is there a way currently to customize this behaviour that I
> > have missed or would this be something the team would be open to
> > exploring in the future?
>
> Just to say that this project hasn't decided whether to expose anything
> on schedulers at this time. There is some basic support in the loom repo
> for experimenting and to get more insight into the topic - is that what
> you are experimenting with?
>
> Timed operations, e.g. timed-Object.wait, sleep, ... have to deal with
> spurious wakeup. Are you looking to advance the time and have these
> operations complete early? Or maybe are looking for all time sources to
> be pluggable? Or maybe you are looking for the scheduler to know that a
> virtual thread is doing a timed operation?
>
> -Alan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20250622/0a050add/attachment.htm>
More information about the loom-dev
mailing list