Is System.nanoTime() consistent across threads?

倖福魔咒の 提交于 2019-11-28 03:01:41

问题


I want to count the time elapsed between two events in nanoseconds. To do that, I can use System.nanoTime() as mentioned here. The problem is that the two events are happening in different threads.


Since nanoTime() doesn't return an absolute timestamp but instead can only be used to calculate time differences, I'd like to know if the values I get on the two different threads are consistent with the physical time elapsed between the two events.


回答1:


It's supposed to be, but due to buggy kernels or hardware, the answer can be no, at least in some environments.



来源:https://stackoverflow.com/questions/2688099/is-system-nanotime-consistent-across-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!