difference between last actual and scheduled fire time

核能气质少年 提交于 2019-12-13 01:25:51

问题


I want to get the delay between the time a job was supposed to execute and the time it actually executed for the most recent execution. For example, if a job was supposed to fire at 8pm and it actually fired at 8.10pm, the result should be 10 minutes.

I know that I can use Trigger.getPreviousFireTime() to get the last time it actually executed, but I can't see any way to get the corresponding scheduled time (e.g. 8pm for the example above), is this possible?


回答1:


Inside your job use the following code:

@Override
public void execute(final JobExecutionContext context) {
    long diffInMillis =
                new Date().getTime() - context.getScheduledFireTime().getTime();
    //...
}

As you probably guessed context.getScheduledFireTime() is the time when job was suppose to run (ideally the difference should be close to 0).

Note that if your job is late more than 10 minutes (configurable) it might not fire at all - it depends on your misfire instruction set up.



来源:https://stackoverflow.com/questions/12249994/difference-between-last-actual-and-scheduled-fire-time

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