Date precision on Windows

Max (Weijun) Wang Weijun.Wang at Sun.COM
Mon Sep 14 12:40:53 UTC 2009


Hi All

Recently one of my Kerberos tests always reports "replay detected"  
error. Turns out the time precision on Windows is quite low.

I've written this tiny program. It calls new Date().getTime() as fast  
as possible and try to see if the output is continuous:

class A {
   public static void main(String[] rags) throws Exception {
     int[] x = new int[100];
     long l = new java.util.Date().getTime();
     while (true) {
       long m = new java.util.Date().getTime();
       if (m - l >= 100) break;
       x[(int)(m-l)]++;
     }
     for (int i=0; i<100; i++) {
       System.out.printf("%5d %d\n", i, x[i]);
     }
   }
}

On Linux and Solaris, there are only 2 to 5 zeros in the output, which  
shows the time is quite continuous on these systems. However, on  
Windows (a x64 system), only 1/16th are non zeros, which shows the  
maximum precision on Windows looks like 16 millisec.

Can this be enhanced?

Thanks
Max




More information about the core-libs-dev mailing list