java - Why is my System.nanoTime() broken? -


On my time, both me and the other developer went to work from a Cor 2 Duo machine to the new Core 2 Quad 9505 ; Windows XP SP3 32-bit is running with both JDK 1.6.0_18.

By doing this, our automated unit tests for some time / data / matrix aggregation codes immediately started to fail, due to which the ridiculous value system appears. Returning from nanotime ()

The test code shown to this behavior, reliably, is on my machine:

  import static org.junit.assert .assertThat; Import organization Matchbox. Import org.junit.Test; Public class nanotext {@Test public throws naught test nanotime (); Exposure {last long sleep = 5000; Long nanose = system Nano time (); Long ago millis = System.currentTimeMillis (); Thread.Sleep (sleepMillis); Long nanotechnology = system. Nano Time () - Nanos First; Long milltank = system Content-time milliseconds () - million ago; Println ("nanosTaken =" + nanosTaken); Println ("millisTaken =" + millisTaken); // Check that it has been slept within 10% of the requested time, (this twice), Matches Close (sleepmillilis, sleep mixtures * 0.1)); AssertThat ((double) nanosTaken, Matchers.closeTo (Ninety gold * 1000000, sleepmill * 1000000 * 0.1)); }}  

Specific output:

  millisextank = 5001 nanotech = 2243785148  

100x yields nano result running in real 33% and 60% of sleep time; Usually around around 40%.

I understand the accuracy of the timer in Windows, and read related threads, though I understand that System.nanoTime () is actually using our: - time passage The time of; More accurate than current timelines ()

Does anybody know why this is returning such crazy results? Is it likely to be a hardware architecture problem (CPU / motherboard has changed on this machine, which is the only major thing)? Is there a problem with Windows HAL with my existing hardware? Is there a JDK problem? Should I Leave Nano Time ()? Do I want to log some bug to another location, or how can I check further, any suggestions on this?

UPDATE 19/07 03:15 UTC : After testing the case of FINNEWA I'm coming into entries such as Googling, something else. It reminded me of some other strange behavior that I was seen yesterday on Friday where Ping was returning negative. So I have added / usepmtimer to my boot.ini and now all tests behave as expected, and my pings are also normal.

I'm a little confused why this was still an issue; From my reading I thought that TSC vs. PMT issues were largely resolved in Windows XP SP3. Could it be because my machine was originally SP2, and SP3 was compromised instead of being originally installed as SP3? I still wonder if I should install the patch as one on one Maybe I should take it from the corporate desktop build team?

The problem was resolved (some open C: \ boot.ini Doubts about the suitability of nano time on the multi-core system by adding / usepmtimer at the end of the string; Forcing Windows to use the Power Management timer instead of TSC. It is an open question that why I need to do it so that I am on XP SP3, as I understood it was the default, though The it was because of the way in which my machine SP went to patch 3.


Comments