RSS Feed for This PostCurrent Article

Java: Time Synchronization Trick in Programming

In previous article, I have written about Java Time Sync Problem. JVM time follows the CPU ticks once it is started even though the application servers are time synced with NTP.

With this in mind, if developer does not use a centralized server to retrieve the time, it would pose a problem.

Image the following scenario,

  1. You have 10 Java applications accessing a database server
  2. Each application servers have been running for some time, and the Java applications time are now few minutes apart
  3. 1 application inserts a record using the current time as the record effective date
  4. Another application retrieves the record and compare the effective date with its current time

In the above scenario, even though your application logic may sound correct, and when it is running in production environment, thing will go wrong.

Trackback URL

Sorry, comments for this entry are closed at this time.