Why does the JVM show more latency for the same block of code after a busy spin pause?

前端 未结 2 1675
无人共我
无人共我 2021-02-08 13:33

The code below demonstrates the problem unequivocally, which is:

The exact same block of code becomes slower after a busy spin pause.

2条回答
  •  臣服心动
    2021-02-08 14:15

    You can probably not rely on the precision of any timer for the accuracy you seem to want, https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#nanoTime-- states that

    This method provides nanosecond precision, but not necessarily nanosecond resolution (that is, how frequently the value changes) - no guarantees are made except that the resolution is at least as good as that of currentTimeMillis().

提交回复
热议问题