It seems System.currentTimeMillis
is not very accurate.
See this sample:
public class MillisTime {
public static void main(String[] args) {
long start = 0;
long end = 0;
while (true) {
if (start == 0) {
start = System.currentTimeMillis();
} else {
long current = System.currentTimeMillis();
if (current != start) {
end = current;
break;
}
}
}
System.out.println("The time interval of your OS: " + (end - start) + "ms");
}
}
The result is (on Windows XP):
The time interval of your OS: 15ms
Why it's not 1ms
? And how to get accurate millis second of current time?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…