Will System.currentTimeMillis always return a value >= previous calls?

后端 未结 5 700
既然无缘
既然无缘 2020-11-27 04:26

https://docs.oracle.com/javase/6/docs/api/java/lang/System.html#currentTimeMillis() says:

Returns the current time in milliseconds. Note that while th

5条回答
  •  Happy的楠姐
    2020-11-27 05:14

    No, it will not always be >= all previous calls.

    • It might not increase every time if you call it several times in quick succession from the same thread (I know this is the = part of >=, but the behavior often surprises people).

    • If you call it several times in quick succession from multiple threads, it might do any number of things -- it could go slightly back in time across threads by a very small amount, depending on implementation and random chance.

    • Most seriously, the value might go back in time by a large amount if the user (rare) or an NTP sync (potentially common) adjusts the system clock.

提交回复
热议问题