Java scheduler which is completely independent of system time changes

半世苍凉 提交于 2019-11-28 07:33:56

There is bug in JVM for overall scheduling during Sytem time changes backward, which also impacts very basic Object.wait & Thread.sleep methods. It becomes too risky to keep Java App running when system time switches back by even certain seconds. You never know what your Java App will end up to.

So we have decided to:

  • Write watch dog script (non Java :)) to check time change.
  • if time switches back by certain amount, shutdown and restart Java app.

Another possibility was to move to 32bit JVM, But we are using JNI and then native libraries used on target platform are not 32bit compatible. Also from our experience 32bit JVM limits our target to 1.6G heap, which is not at all sufficient for us.

I know ours is not most elegant solution, but untill JVM is fixed or some better solution is found, there doesn't seem to be any other way.

Edited: We are also considering 1st suggestion from Chris in addition to above solution:

  • Configure NTP to never have a big time jump. Only slew the time slowly. Only apply big time jumps manually during downtime.

I worked against the same problem and have not found a solution. I looked at Quartz and all of the built-in JRE methods. The nanotime methods may use per-CPU monotonic clocks, but you risk big jumps if the threads are migrated to another CPU, I believe. My conclusions were the following:

  1. Configure NTP to never have a big time jump. Only slew the time slowly. Only apply big time jumps manually during downtime.
  2. Use multiple shorter timeouts, and require two timeouts to declare a remote machine dead. This won't help if you have just one system timing itself, but can help with multiple systems
  3. use a remote machine on purpose to send you periodic wakeups. If your own clock goes backward between wakeups, then you know all of your timers are going to fire late.

Basically, this is a huge pain but there are no silver bullets.

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