0

I have 2 linux servers and code to run according to the current time. A loop should run from 00:00 to 23:55 local time.

Calendar c = Calendar.getInstance();
if (c.get(Calendar.HOUR_OF_DAY) > 22 && c.get(Calendar.MINUTE) >= 55) {
    /* ... */
    /* ... */
} else {
    Thread.sleep(1000 * timeToSleep);
}

I have the above given logic. But since the BST has come into effect since late march this code has been posing a problem in 1 server. While in server1 this starts at 00:00 and ends at 23:55 which is correct. In server2 the code is not ending at 23:55 instead 00:55.

We assumed that the code is still picking GMT (in winters for U.K.) but then the other server should have faced the problem. Why is it happening on 1 server this runs fine while on other wrong time is picked. All the configs what i have seen are more or less same for both the servers.

Aconcagua
  • 24,880
  • 4
  • 34
  • 59
shruti rawat
  • 241
  • 1
  • 7
  • 19
  • Have you checked that both servers actually are configured in the same time zone? If not, switching the time zone in the calendar instance could set time back one hour. – Aconcagua Apr 21 '16 at 07:49
  • yes.. the timezone seems to be same as printed in logs. as when i do getdate the time printed is correct in both the servers – shruti rawat Apr 21 '16 at 07:55
  • Still print/log the time zone of the calendar object, just to be on the safe side. Possibly, something has gone wrong with that. Is there a need to explicitly set the timezone to BST? Have you tried just to trust the calendar instance as is? – Aconcagua Apr 21 '16 at 07:59
  • actaully this process is running at U.K. time. So when daylight started all servers were changed to BST and then is my code started behaving strangely on 1 server. Though I am unable to repsoruce the issue on my local as well as other server. The time zone for one server is GB while for other is GB-Eire. But is think its more or less same. isn't it? – shruti rawat Apr 21 '16 at 08:04
  • Possibly not reproducible because only an issue when OS actually DOES switch time. Still I would try simply not to set the time zone explicitely. – Aconcagua Apr 21 '16 at 08:15
  • i am not setting timezone explicitely, in the code at least. I am just setting time i.e. 23:55 irrespective of timezone – shruti rawat Apr 21 '16 at 08:31
  • And what is this: `c.setTimeZone(TimeZone.getTimeZone("BST"));` – Aconcagua Apr 21 '16 at 08:36
  • oops my bad i have pasted the tetsing code. Corrected it now. – shruti rawat Apr 21 '16 at 08:46
  • Still I would log out c.getTimeZone().getDisplayName() somewhere to exclude possible error with that. Have you control over the server? You then could set time back to right before switching from winter to summer time, this could allow to reproduce the error. Debugging might give you additional insight (http://stackoverflow.com/questions/975271/remote-debugging-a-java-application). – Aconcagua Apr 21 '16 at 10:09

0 Answers0