I'm trying to produce monotonic time in long since epoch using time4j v5.6 using below test code
But output is not expected. Did I miss any initialization of the library? My objective is to produce monotonic time but don't need high precision as this can be executed on client side either linux/windows
import net.time4j.SystemClock;
import java.time.Instant;
public class MonotonicClock {
public static void main(String[] args) {
SystemClock systemClock = SystemClock.MONOTONIC;
long t1 = systemClock.currentTimeInMicros() * 1000;
boolean failed = false;
for (int i = 0; i < 1000_000; i++) {
long t2 = systemClock.currentTimeInMicros() * 1000;
if (t2 < t1) {
System.out.println(Instant.ofEpochSecond(0, t2) + "<" + Instant.ofEpochSecond(0, t1));
failed = true;
}
t1 = t2;
}
if(failed) {
System.err.println("Test Failed");
}else {
System.out.println("Test Passed");
}
}
}