<!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 13/10/2025 18:52, Mengyang Li wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAJ_HiMtNENbftbhenwfGY=Y48vPsepWaLMk4YwXeV1sBoPc+GQ@mail.gmail.com">
<div dir="ltr">:
<p class="gmail-p1">I came up with a new idea — what if we
provide an additional <span class="gmail-s1">Delay</span>
interface?</p>
<p class="gmail-p1">If the current scheduler implements this
interface, we can use the scheduler’s own <span class="gmail-s1">delay</span> method.</p>
<p class="gmail-p2"><span class="gmail-s2">Otherwise, we fall
back to `</span>DelayedTaskSchedulers.schedule`<span class="gmail-s2">.</span></p>
<p class="gmail-p1">Currently, Loom only optimizes <span class="gmail-s1">ForkJoinPool</span> for this case.</p>
<p class="gmail-p1">``` java</p>
<p class="gmail-p1">VirtualThreadScheduler scheduler(boolean
revealBuiltin) {<br>
if (scheduler instanceof BuiltinDefaultScheduler builtin
&& !revealBuiltin) {<br>
return builtin.externalView();<br>
} else {<br>
return scheduler;<br>
}<br>
}</p>
<p class="gmail-p1">```</p>
<p class="gmail-p3">
</p>
<p class="gmail-p1">But if I use Netty’s <span class="gmail-s1">EventLoop</span>
as the scheduler, being able to implement delay based on the
event loop would be fantastic.</p>
</div>
</blockquote>
<br>
For now, the experimental/prototype for custom schedulers will only
call out to the custom scheduler to execute a task that starts or
continue a virtual thread. The VirtualThreadScheduler interface
could be extended to allow the custom scheduler to take on delayed
tasks but these are not virtual thread tasks, they are tasks to
support timed-Object.wait for timed-park. You are right that a SPTE
based implementation is used in the JDK when there is a custom
scheduler configured. Is this causing an issue? Timeouts are usually
cancelled, >99% in many cases, so I'd like to understand if your
workloads are different, maybe you have more scenarios where a
timeout occurs?<br>
<br>
-Alan<br>
</body>
</html>