手动触发Quartz作业 [英] Firing Quartz jobs manually
问题描述
我们在应用程序中配置了几个Quartz作业.在开发过程中,我们让石英调度程序处于待机状态-但是,有时我们想手动启动作业(出于开发目的).如果我调用fireTrigger,它会告诉我需要启动调度程序.但是,如果我启动调度程序,它将立即调度所有其他作业,这不是我想要的(因为它们可能会在调试手动执行的作业时触发).
We have several Quartz jobs configured in our application. During development, we leave the quartz scheduler in standby - however, we sometimes want to start a job manually (for development purposes). If I call fireTrigger, it tells me I need to start the scheduler. However, if I start the scheduler, it will also immediately schedule all the other jobs, which is not what I want (since they may trigger while I'm debugging the manually fired job).
启动调度程序时,我可以暂停所有触发器,但随后必须处理断火指令等.
I could pause all triggers when I start the scheduler, but then I have to deal with misfire instructions etc.
是否有一种简单的方法可以手动启动作业,而不必处理暂停和断火(即,即使调度程序处于待机状态,fireTrigger仍然可以工作)吗?
Is there a simple way to fire off a job manually without having to deal with pausing and misfires (i.e. a fireTrigger which works even if the scheduler is in standby)?
推荐答案
这是您手动触发作业所需的循环:
this is the loop you will require to fire the job manually:
SchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
Scheduler scheduler = stdSchedulerFactory.getScheduler();
// loop jobs by group
for (String groupName : scheduler.getJobGroupNames()) {
// get jobkey
for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
String jobName = jobKey.getName();
String jobGroup = jobKey.getGroup();
scheduler.triggerJob(jobName, jobGroup);
}
}
这篇关于手动触发Quartz作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!