tags:

views:

1375

answers:

2
+2  Q: 

Java NTP client

I need my software to communicate with an NTP server to determine the local clock offset. I have tried using the org.apache.commons.net.ntp package, but its implementation is rather poor when running on Windows, because of the use of System.currentTimeMillis() to determine the time before and after the NTP packet exchange. As you may or may not know, this value is only updated when the system clock ticks, which on most modern Win2k3 servers is at 64Hz or every 15.625ms. This greatly limits the accuracy of the clock offset calculation.

Ntpd uses the CPU high-frequency timer to interpolate between system clock ticks, and achieve much higher resolution time. Do you know of a Java implementation that uses this or a similar technique? Or do you know of any other NTP implementation other than Apache's?

+2  A: 

If you're using Java 5 or above, can you use System.nanoTime() to perform a more accurate measurement of time offsets ? You'd have to modify your existing NTP code, but you should have the source for it, and I wouldn't expect this to be difficult.

Brian Agnew
Yes, System.nanoTime() accesses the high-frequency timer, and I would expect this to be used for timestamping in a decent Java NTP implementation. However, this is non-trivial so I am hoping someone else has already done and debugged it.
Matt Howells
Yes. I couldn't find any obvious implementations though. A chance for fame and respect, maybe ? :-)
Brian Agnew
+2  A: 

there is a NTP Java implementation on support.ntp.org

dfa
Alas, it is a naive implementation of SNTP. But +1 for finding it, thanks.
Matt Howells