Deadlock issues with non-monotonic time
DaveJarvis opened this issue · comments
Dave Jarvis commented
There are potential deadlocks that I've encountered across a few code bases now. The reduced form resembles:
long start = System.currentTimeMillis();
boolean blocked = System.currentTimeMillis() - start < TIMEOUT;
If the system time changes non-linearily (e.g., NTP daemon updates the time), then it's possible that the code will block indefinitely, or cause loops to terminate unexpectedly.
The recommended alternative is to use the monotonic System.nanoTime()
for blocking loops.
Would this make for a possible check to add to SpotBogs?