简体   繁体   English

在非周期性时间间隔内调用Quartz Scheduler

[英]Calling Quartz Scheduler In Non Periodic Time Interval

In quartz scheduler I have a doubt 在石英调度程序中,我有一个疑问

For example 例如

If we schedule job for every 5 minutes or 10 minutes or 2 hours it is ok we call scheduler using regular time interval like below no problem, 如果我们每5分钟,10分钟或2小时安排一次作业,可以的话,我们会使用固定的时间间隔(如下面的问题)来调用计划程序

    SimpleTrigger simpleTrigger = new SimpleTrigger("mytrigger",sched.DEFAULT_GROUP,new Date(),null,SimpleTrigger.REPEAT_INDEFINITELY,30L*5000L);

But,If I schedule job @ 2'0 clock and 3'0 clock today then,tommorow I change it to 5'0 clock and 7'0 clock and 11'0 clock, my doubt is if fixed interval we call it in above way but it not fixed or periodic interval how do we handle it. 但是,如果我今天将作业安排为@ 2'0时钟和3'0时钟,那么明天我将其更改为5'0时钟,7'0时钟和11'0时钟,我的疑问是是否在上面将其称为固定间隔方式,但它不是固定的或周期性的间隔,我们该如何处理。 Any suggestions or Ideas or examples regarding my query.... 关于我的查询的任何建议或想法或示例。

What you can do is define the intervals in a file or DB and read it from there. 您可以做的是在文件或数据库中定义间隔,然后从中读取间隔。

Also define a JobListener . 还定义一个JobListener

Store the interval values in the JobDataMap and every time the job starts, use the listeners method jobToBeExecuted() and read the values from the file/DB and compare it with the values in the JobDataMap . 将间隔值存储在JobDataMap中,并且每次作业启动时,使用侦听器方法jobToBeExecuted()并从文件/ DB中读取值,并将其与JobDataMap的值进行比较。

If they are the same, then no update was done and the job runs, if it was changed, reschedule the job using Scheduler.rescheduleJob(TriggerKey triggerKey,Trigger newTrigger) . 如果它们相同,则不执行任何更新,并且作业运行(如果已更改),请使用Scheduler.rescheduleJob(TriggerKey triggerKey,Trigger newTrigger)重新Scheduler.rescheduleJob(TriggerKey triggerKey,Trigger newTrigger)作业。

Note that there is a little problem with this method, the configuration will only change once the job runs, so even though you update the file/DB the next run would still be in the old time, and only the run after that would be in the new time. 请注意,此方法有一个小问题,该配置仅在作业运行后才会更改,因此,即使您更新文件/数据库,下一次运行仍将是旧时间,而之后的运行将处于旧时间。新的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM