How to cancel a scheduled Quartz job in Spring

十年热恋 提交于 2019-12-20 10:29:12

问题


I'm using Spring to inject a Quartz scheduler (abstracted with Spring's TaskScheduler interface) into my app that loads jobs configured from a database at startup.

It adds each job in the scheduler something like this:

TaskScheduler taskScheduler = ...;//injected    
Runnable runableThing = ...;
String cronExpression = ...; //from DB
taskScheduler.schedule(runableThing, new CronTrigger(cronExpression));

my question is this: Is it possible to specify something like a job_id that can subsequently be used to cancel the job/trigger - say in response to a user selecting the job to be cancelled in the web interface?

I've looked at the Spring docs and can't see a way to do this.

Any ideas gratefully received.


回答1:


Unscheduling a Particular Trigger of Job

scheduler.unscheduleJob(triggerName, triggerGroup);

Deleting a Job and Unscheduling All of Its Triggers

scheduler.deleteJob(jobName, jobGroup);

Ref: http://www.opensymphony.com/quartz/wikidocs/UnscheduleJob.html




回答2:


ScheduledFuture<V> job = taskSchedule.schedule(runableThing, new CronTrigger(cronExpression))
job.cancel(true); 


来源:https://stackoverflow.com/questions/4269754/how-to-cancel-a-scheduled-quartz-job-in-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!