且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java EE 7:设置为persistent = true时获取@Schedule日期

更新时间:2023-12-03 13:11:52


有没有办法检索应该启动@Schedule作业的日期??? / p>

Is there any way to retrieve the date when the @Schedule job should have been launched???

我认为答案是否定的,没有。

I think the answer is no, there isn't.

规范定义了必须由Container实现的三个接口。
这些界面是: TimerService ,计时器和 TimerHandle
如您所见,其中没有人(特别是Timer)公开您需要的方法
。因此,不会强制Java EE兼容服务器实现此行为。

The specification defines three interfaces that must be implemented by the Container. These interface are: TimerService, Timer and TimerHandle. As you can see, no one of them (specially Timer) exposes the method that you need. Therefore, a Java EE compliant server is not forced to implement this behavior.

您可能应该自己实现提供此要求的解决方案。
例如,您可以存储执行最后一个回调方法
时的时间戳,并使用此时间戳来确定时间段(而不是减去当前日期的1小时)

Probably you should implement by yourself a solution that provides this requirement. For example, you could store the timestamp when the last callback method was executed and use this timestamp for determining the period of time (instead of subtract 1 hour to the current date)


...如果服务器在5小时内停止,该作业将启动5次......

...if the server has been stopped during 5 hours, the job will be launched 5 times...

请注意,您不能依赖此


18.4.3计时器到期和超时回调方法
...在干预
时间内已过期的任何间隔持久定时器或基于调度的持久定时器必须在重新启动时调用相应的超时回调方法至少一次