Closed jabrena closed 4 years ago
private static final AtomicLong LAST_TIME_MS = new AtomicLong();
public static long getEpoch() {
long now = System.currentTimeMillis();
while(true) {
long lastTime = LAST_TIME_MS.get();
if (lastTime >= now) {
now = lastTime + 1;
}
if (LAST_TIME_MS.compareAndSet(lastTime, now)) {
return now;
}
}
}
https://stackoverflow.com/questions/9191288/creating-a-unique-timestamp-in-java/9191383
Tested alternative