Is there an off-the-shelf clock synchronization solution for Java?

折月煮酒 提交于 2019-12-05 04:01:38

With distributed programming, clock synchronisation is often not enough. you might want to build a logical time framework (such as the Lamport or vector clocks or Singhal-Kshemkalyani methods ... and there are loads more to keep causality in sync across machines). Which you choose often depends on the application and required causality between events.

Clocks are sync'd to ensure concurrent events are kept in the right sequential order. There are other ways to do this than keeping the system clock synchronized ... which unless they share a common physical clock ... is quite tricky.

In terms of NTP error margin, there are solutions:

my recommendation:

Read: Distributed Computing: Principles, Algorithms and Systems

Especially: Chapter 3, logical time

Edit

Further to Cheeso's post, I found

http://www.uniforum.org/publications/ufm/apr96/opengroup.html

http://sourceforge.net/projects/freedce

There maybe DCE Java bindings out there.

I'd really just use NTP. It's pretty accurate even over the internet, and on a LAN it should be even better. According to Wikipedia[1],

NTPv4 can usually maintain time to within 10 milliseconds (1/100 s) over the public Internet, and can achieve accuracies of 200 microseconds (1/5000 s) or better in local area networks under ideal conditions.

so it may be good enough for your needs if your conditions are "ideal" enough. NTP has been around long enough that pretty much everything works with it. I don't see any reason to do this through Java rather than the OS. If the OS is synced up, so will be Java.

[1] Wikipedia: Network Time Protocol

I encountered this thread after trying something on my own (should have searched first!) http://snippets.dzone.com/posts/show/11345 - may be a good method, may be bad, but it's distributed (serverless) which is nice.

The old DCE ("Distributed Computing Environment") used to have a distributed time synch solution, with all those capabilities. It was called DTS. The admin could configure the set of machines to sync, and the latency or uncertainty was calculated and available. If any machine got out of sync, it's clock was slowly adjusted until it was in synch again. There was a guarantee that time on any machine would never be adjusted backward (in violation of basic physics). The network needed at least one NTP input in order to stay synched with "the real world".

I don't know what happened to that time synch stuff, or the DCE code in general.

Seems to me you don't need a solution "in Java". You need to sync the clocks of a set of distributed machines. The Java app is just the thing that runs on the machines.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!