Is System.nanoTime() Still Flawed on Multi-Core Systems?
The blog post "Beware of System.nanoTime() in Java" raised concerns about the reliability of System.nanoTime() on x86 architectures, where the CPU-specific counter it utilizes could lead to negative time measurements due to thread scheduling across differing processors with asynchronous counters.
However, a 2011 response from a Sun engineer (now Oracle) clarified that this issue was addressed in Windows XP Service Pack 2 and is no longer a concern on modern Windows and Linux systems.
Windows:
Linux:
Other Platforms:
The provided response does not address SPARC or Solaris systems. However, it is reasonable to assume that these platforms have also implemented similar mechanisms to ensure consistent timekeeping across multiple processors.
It is important to note that this information was accurate as of 2011. For the most recent updates on the implementation and behavior of System.nanoTime(), please refer to up-to-date documentation and community discussions.
The above is the detailed content of Is System.nanoTime() Truly Reliable on Modern Multi-Core Systems?. For more information, please follow other related articles on the PHP Chinese website!