Class VirtualThreadsIdle
java.lang.Object
ai.badmonkey.agentspaces.test.VirtualThreadsIdle
Waits until no virtual thread in this JVM runs or waits to run (srad/agentspaces-event-loop.md EL-Q-TST-03): the
settle a sim fleet on
VirtualTime needs for the work that is not a task of its time, such as a content
swarm's frame handlers, which run one virtual thread per frame. VirtualTime.advance(Duration) settles its own tasks;
this settles the rest, so a fleet ticks again only once the frames of the last tick are handled, with no fixed sleep.
It reads the JDK's virtual-thread scheduler (jdk.management.VirtualThreadSchedulerMXBean, JDK 24 and
later): idle is no virtual thread mounted (other than the caller's own) and none queued, read twice in a row. A
thread parked on a lock, a sleep or a wait is idle. On a JDK without the bean it only yields. Call it from the test's
thread between ticks; JUnit runs one test at a time in a JVM here, so the threads it sees are the test's.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanWhether this JDK reports its virtual-thread scheduler, soawait(Duration)really waits.static booleanWaits until no virtual thread runs or waits to run, for at mostmaxof real time.
-
Method Details
-
available
public static boolean available()Whether this JDK reports its virtual-thread scheduler, soawait(Duration)really waits. -
await
Waits until no virtual thread runs or waits to run, for at mostmaxof real time.- Parameters:
max- the longest wait; a bound for a thread that spins, not a pause- Returns:
- true once idle; false at the bound or without the bean
-