How to set new job each time with different interval

时间:2015-07-08 15:37:48

标签: java quartz-scheduler

I'm pretty new to Quartz and I've come a cross the following requirement:

I need to create a scheduler that schedules single job that each time it ends it rescheduled but with calculated interval time.

For example: 1. Start job that ends after 15minutes, then when finished reschedule it to end after 1Hour, when finished reschedule it to end after 45 minutes...and so on...

The point is that when job finishes I dynamically calculate the next interval and need to fire the event again.

How to accomplish that with Quartz?

Thanks.

1 个答案:

答案 0 :(得分:1)

如果您可以第一次明确触发它,例如

 for row in Group.select():
    group_data = process_group(row.link)
    Group.update(name=group_data[0], type=group_data[1], member=group_data[2]).where(Group.id==1)

for row in Group.select():
    group_data = processl_group(row.link)
    Group.update(name=group_data[0], type=group_data[1], member=group_data[2]).where(Group.link==row.link)

并对作业类进行编码,使其在完成主要工作后,计算下一个触发时间并在作业退出之前对其进行计划。像

这样的东西
scheduler.addJob(jobDetail, true);
scheduler.triggerJob(jobName, groupName); //(1)

请注意,代码段(1)中的作业触发器会在完成后删除作业。这意味着您必须在(2)中安排它,就像调度程序涉及的新工作一样。