Is System.nanoTime() consistent across threads?(System.nanoTime() 跨线程是否一致?)
问题描述
我想以纳秒为单位计算两个事件之间经过的时间.为此,我可以使用 System.nanoTime() 提到的 这里.问题是这两个事件发生在不同的线程中.
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.
由于 nanoTime() 不返回绝对时间戳,而是只能用于计算时间差异,我想知道我得到的值是否两个不同线程上的两个事件之间经过的物理时间是一致的.
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.
推荐答案
它是 应该是,但由于内核或硬件有问题,答案可能是否定的a>,至少在某些环境中.
It's supposed to be, but due to buggy kernels or hardware, the answer can be no, at least in some environments.
这篇关于System.nanoTime() 跨线程是否一致?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:System.nanoTime() 跨线程是否一致?
基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
