问题
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!
回答1:
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);
来源:https://stackoverflow.com/questions/20370429/grails-stop-or-reschedule-a-job