Quartz-改变当前时间是如何确定的?
是否可以改变 Quartz 调度程序决定当前时间的方式?
我正在开发一个基于服务的应用程序,其中包括一个时间服务,负责按需提供当前时间(以便我们可以控制当前时间以进行测试)。
我们的调度服务在底层使用 Quartz。如果调度在测试时尊重“正确的”当前时间,而不是由 System.currentTimeMillis() 或类似方法确定的时间,那就太好了。
(我认为这个问题的答案可能表明我不能这样做,但我希望我错了......)
我正在使用 Quartz 版本 2.0.0。
Is it possible to change how a Quartz scheduler decides what the current time is?
I am developing a service-based application, including a time service that is responsible for providing the current time on demand (so that we can control the current time for testing purposes).
Our scheduling service uses Quartz under the hood. It would be nice for scheduling to respect the 'correct' current time when under test, rather than the time as determined by System.currentTimeMillis()
or similar.
(I think that the answer to this question might suggest that I can't do this, but I hope that I'm wrong...)
I'm using Quartz version 2.0.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是定义您自己的调度程序来包装(或继承)StdScheduler。在重写的
scheduleJob(...)
方法中,您可以使用包装器实现来包装提供的Trigger
,例如,在其中重写getStartTime()< /code> 和/或
getNextFireTime()
方法返回包装的触发器返回值加上或减去某个间隔,该间隔表示“测试”时间与“实际”时间的偏移量。One way would be to define your own Scheduler that wraps (or inherits) the StdScheduler. In your overrided
scheduleJob(...)
method, you wrap the suppliedTrigger
with a wrapper-implementation where you, for instance, override thegetStartTime()
and/orgetNextFireTime()
methods to return the wrapped triggers return value plus or minus some interval that represents the offset of your "test" time against the "real" time.你的问题的答案是“否”,你不能这样做。
早些时候,Quartz 试图解决这种需求,但必须有如此多具有如此多不同生命周期的组件(实例化器等)需要确定当前时间,以至于它所需的管道变得非常笨重,因此被放弃。
The answer to your question in NO, you cannot do that.
Earlier on Quartz tried to account for such a need, but there got to be so many components with so many different lifecycles (instantiators, etc.) that need to determine current time that the plumbing necessary for it became very unwieldy and it was given up.