<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<br>
<br>
<div class="moz-cite-prefix">On 05/07/2025 21:25, Ryan Yeats wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAO4jUyUObxU=NuMLabfEHt2MSBiWzjWEfncg0YKQNsukoKUgjg@mail.gmail.com">
<div dir="ltr">:
<div>
<div>
<ol>
<li>Its not easy to replace the virtual thread scheduler</li>
<li>The aforementioned scheduler has no understanding of
delays so any Thread.sleep or Object.wait introduces
continuations back into the scheduled execution pool
non-deterministically. This affects the execution order
so bugs can't always be reproduced.</li>
<li>IO also introduces continuations back to the scheduler
execution pool non-deterministically.</li>
</ol>
<div>The first issue can currently be solved by using
reflection to make the <a href="https://github.com/ryeats/loom-dst/blob/main/src/main/java/org/example/SchedulableVirtualThreadFactory.java" moz-do-not-send="true">virtual thread constructor public</a>. The
second issue can currently be solved by controlling system
time by replacing the byte code for all calls to
System.nanoTime(), System.onCurrentTimeMillis() and
Instant.now() <a href="https://github.com/cmu-pasta/fray/blob/main/instrumentation/base/src/main/kotlin/org/pastalab/fray/instrumentation/base/visitors/TimeInstrumenter.kt" moz-do-not-send="true">using an agent at runtime</a>.
The third likely has no general solution but I am
interested in hearing ideas.</div>
</div>
<br>
</div>
</div>
</blockquote>
There are experimental changes in the loom repo to allow the virtual
thread scheduler be replaced or wrapped. There is also a prototype
API to set a scheduler when creating a virtual Thread. There is a
doc in the repo with more on this [1]. This project hasn't decided
whether to expose anything so any reports from experiments would be
useful to hear about.<br>
<br>
-Alan<br>
<br>
[1]
<a class="moz-txt-link-freetext" href="https://github.com/openjdk/loom/blob/fibers/loom-docs/CustomSchedulers.md">https://github.com/openjdk/loom/blob/fibers/loom-docs/CustomSchedulers.md</a><br>
</body>
</html>