0

This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change. Differences in successive calls that span greater than approximately 292 years (263 nanoseconds) will not accurately compute elapsed time due to numerical overflow.

我不确定这些值如何不精确以及数字溢出背后的逻辑。

4

1 回答 1

3

此方法提供纳秒级精度,但不一定提供纳秒级精度

该方法会给你一个以纳秒为单位的数字,但它使用的时钟实际上可能无法跟踪纳秒。一些最后的数字可能是错误的。在使用此方法的应用程序中,这种不准确性很好。

由于数值溢出,超过大约 292 年(263 纳秒)的连续调用的差异将无法准确计算经过的时间。

2^63 纳秒对于 a 来说太多了long。如果你的代码运行了 292 年,那么时间已经过去了,Java 无法表达它运行了多长时间。

于 2013-12-12T16:02:26.723 回答