开发者

Quartz - change how the current time is determined?

开发者 https://www.devze.com 2023-03-30 22:52 出处:网络
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 t

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 u开发者_Go百科nder 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.


One way would be to define your own Scheduler that wraps (or inherits) the StdScheduler. In your overrided scheduleJob(...) method, you wrap the supplied Trigger with a wrapper-implementation where you, for instance, override the getStartTime() and/or getNextFireTime() 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号