Switch to monotonic System.nanoTime()

This commit is contained in:
Tony Garnock-Jones 2024-04-30 21:25:34 +02:00
parent 1d744181ec
commit 5d2613873c
2 changed files with 5 additions and 5 deletions

View File

@ -170,11 +170,11 @@ public class Promise<T> implements Future<T> {
if (delay == -1) {
while (this.isPending()) this.wait();
} else {
long targetTime = System.currentTimeMillis() + unit.toMillis(delay);
long targetTime = System.nanoTime() + unit.toNanos(delay);
while (this.isPending()) {
long now = System.currentTimeMillis();
long now = System.nanoTime();
if (now >= targetTime) throw TIMEOUT_WAITING_FOR_PROMISE_RESOLUTION;
this.wait(targetTime - now);
this.wait(TimeUnit.NANOSECONDS.toMillis(targetTime - now));
}
}
}

View File

@ -47,7 +47,7 @@ public class Main extends Entity {
t.message_(_forwarders.get(0), new IForwarder.SetPeer(_forwarders.get(_nActors - 1)));
t.later(t0 -> {
t0.log().info("Start");
this._startTime = System.currentTimeMillis();
this._startTime = System.nanoTime();
_forwarders.forEach(a -> t0.message_(a, new IForwarder.HandleMessage(0)));
});
}
@ -57,7 +57,7 @@ public class Main extends Entity {
if (body instanceof IForwarder.HandleMessage) {
this._remainingToReceive--;
if (this._remainingToReceive == 0) {
double delta = (System.currentTimeMillis() - this._startTime) / 1000.0;
double delta = (System.nanoTime() - this._startTime) / 1000000000.0;
long nMessages = (long) _nActors * (long) _nRounds;
double hz = nMessages / delta;
turn.quit();