I have some tasks that are executed with the help of Java Quartz Jobs, but I need to stop some tasks by some condition in my code. I read that this can be done via Interrupt
In Quartz 2.1 with Spring you can:
@Autowired
private Scheduler schedulerFactoryBean; //injected by spring
...
...
List currentlyExecuting = schedulerFactoryBean.getCurrentlyExecutingJobs();
//verifying if job is running
for (JobExecutionContext jobExecutionContext : currentlyExecuting) {
if(jobExecutionContext.getJobDetail().getKey().getName().equals("JobKeyNameToInterrupt")){
result = schedulerFactoryBean.interrupt(jobExecutionContext.getJobDetail().getKey());
}
}