1

I am facing a problem in Java scheduler. I am using a TimerTask, when I schedule a task at some particular time and change the OS time, the TimerTask thread is not getting the time change update. So the scheduled task is not happening on the specified time. I faced this issue when i was working on daylight saving.

mort
  • 10,940
  • 14
  • 45
  • 92
Madhusudhan
  • 35
  • 1
  • 1
  • 6
  • What do you mean by "change the time"? –  May 04 '15 at 12:17
  • when the day light change happens Time will reset to 1 hour back or forward. When this change happens will the thread gets notified. – Madhusudhan May 06 '15 at 08:30
  • when the day light change happens Time will reset to 1 hour back or forward. When this change happens will the thread gets notified. Lets say at 10 AM thread will go to wait and i made it to execute the task at 11AM, but between 10AM and 11AM Time reset back 1 hour. If the time reset happens at 10:30AM to 9:30AM, Then my task that i intended to execute at 11AM will execute at 10AM only because i made it to wait for 1 hour. My question is whether thread get the time change notification and execute at 11AM only or thread will execute at 10AM. – Madhusudhan May 06 '15 at 08:51
  • Please show some code! – OldProgrammer May 07 '15 at 11:55

1 Answers1

0

The general problem is probably the fact, that the Date's millis since 1970 UTC is daylight-time change independent.

To get information about the current time - see this answer: How to tackle daylight savings using Timezone in java

How to implement it? Write an observer in a separate thread which checks the time every few seconds, or add such task to cron (Quartz?). Check the timezone offset between each call. If they change, use the event to reinitialize your app however necessary.

Community
  • 1
  • 1
Dariusz
  • 19,750
  • 7
  • 65
  • 104