问题描述
我以这种方式动态调度作业:
$ b
JobClass.schedule(Long interval,Integer repeatCount,Map params)
$ b $ p
稍后,我想停止运行作业,然后根据用户操作重新启动它们。
我怎么能阻止这个触发器?
确实停止它的唯一方法是 谢谢! 您可以使用具有方法unscheduleJob的Scheduler类,它只删除所有与作业绑定的触发器。对于调度程序类对象: 服务中注入 使用代码取消计划作业 JobClass.removeJob()$
$ b
def jobManagerService
jobManagerService.getQuartzScheduler()。unscheduleJob(TriggerKey triggerkey)
开始作业调度:只需为同一作业创建一个新的触发器并安排它。
触发器触发器= TriggerBuilder.newTrigger()
.withIdentity(triggerName,triggerGroupName)
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withIntervalInSeconds())
.forJob(JobKey.jobKey(jobName,groupName))
.build()
jobManagerService.getQuartzScheduler()。scheduleJob(trigger);
I am dynamically scheduling jobs, at this way:
JobClass.schedule(Long interval, Integer repeatCount, Map params )
Later I want to stop the job from running, and then restart them again according to the users actions.
How could I stop this trigger?
The only way that did actually stop it was JobClass.removeJob()
, but I wasn;t able to start it again later, so I need something else.
Thanks!
you can use Scheduler class having methods unscheduleJob which just delete all the triggers bind with the job. For scheduler class object:
Inject in service
def jobManagerService
use the code to unschedule the job
jobManagerService.getQuartzScheduler().unscheduleJob(TriggerKey triggerkey)
to start the job scheduling: just create a new trigger for the same job and schedule it.
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(triggerName, triggerGroupName)
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withIntervalInSeconds())
.forJob(JobKey.jobKey(jobName, groupName))
.build()
jobManagerService.getQuartzScheduler().scheduleJob(trigger);
这篇关于Grails - 停止或重新安排工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!