如何在Quartz中重新安排作业执行间隔? [英] How to reschedule the job execution interval in Quartz?

查看:87
本文介绍了如何在Quartz中重新安排作业执行间隔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Quartz有点新意。有没有办法更新已提交的Quartz作业的作业执行间隔?此间隔是否立即更新?在重新安排它之后你是否必须再次开始这项工作?

I am a bit new to Quartz. Is there a way to update the job execution interval for an already submitted Quartz job? Does this interval get updated immediately? Do you have to start the job once again after rescheduling it?

我发现以下链接但我不知道哪些库是我的石英罐子的代码不包含链接中使用的某些类。此外,triggerKey方法来自哪里?这是某种静态导入吗?

I found the following link but I don't know which libraries is the code reffering to since my quartz jars don't contain some of the classes used in the link. Also, where did the triggerKey method come from? Is this some kind of a static import?

http: //quartz-scheduler.org/documentation/quartz-2.x/cookbook/UpdateTrigger

我想将作业执行间隔更新为非常大的我的一个JUnit测试用例中的数字,因为我不希望该作业干扰被测试类的状态。一旦测试用例完成,我想将作业执行间隔重置为将在生产中使用的实际值

I want to update the job execution interval to a very large number in one of my JUnit test cases since I don't want the job to interfere with the state of the class under test. Once the test case completes, I want to reset the the job execution interval to the actual value that will be used in production

推荐答案

您必须通过创建新触发器来重新安排作业。

You have to reschedule the job by creating a new trigger.

public void execute(JobExecutionContext context) throws JobExecutionException {
    Trigger newTrigger = what_ever_you_want;
    Trigger oldTrigger = context.getTrigger();
    Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
    scheduler.rescheduleJob(oldTrigger.getKey(), newTrigger);
}

这将用新的触发器触发时间替换相同的作业。

This will replace the same job with a new trigger fire time.

这篇关于如何在Quartz中重新安排作业执行间隔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆