开发者

Java time sync problems multiple time zone clients single database server

开发者 https://www.devze.com 2023-02-16 04:38 出处:网络
Image the following scenario, You have 10 Java applications accessing a database server Each application servers have been running for some time, and the Java applications time are now few minutes a

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.

How can i solve this?


Use NTP to synchronise the times of the machines.

If that's not an option for some reason, use only the server's date and time (for example, by using SQL's NOW function or similar both in inserts and as an extra column in selects).

0

精彩评论

暂无评论...
验证码 换一张
取 消