System.currentTimeMillis vs System.nanoTime

后端 未结 10 1231
后悔当初
后悔当初 2020-11-21 22:56

Accuracy Vs. Precision

What I would like to know is whether I should use System.currentTimeMillis() or System.nanoTime()<

10条回答
  •  梦如初夏
    2020-11-21 23:17

    Since no one else has mentioned this…

    It is not safe to compare the results of System.nanoTime() calls between different threads. Even if the events of the threads happen in a predictable order, the difference in nanoseconds can be positive or negative.

    System.currentTimeMillis() is safe for use between threads.

提交回复
热议问题