Hemant Metalia
Hemant Metalia

Reputation: 30698

how to suspend job in quartz scheduler?

Hi i am creating an application that executes the method of a class based on a cron expression. For that i am using spring quartz in which i have to configure all these stuffs in my spring-file it works fine and jobs are executing based on the cron expression, But now i want to suspend the next execution of particular job in java class based on the choice of a user from UI. Then is there any way to do this ??

can i get the details of all running job it the context ? if so then i can filter the jobs and try to suspend that job for next execution.

Upvotes: 4

Views: 15072

Answers (4)

k_o_
k_o_

Reputation: 6308

If you got hold of the SchedulerFactoryBean by injection or somehow else there are the convenience methods:

schedulerFactoryBean.getScheduler().standby();
schedulerFactoryBean.getScheduler().start();

When using Quartz directly also this works:

@Autowired
private Scheduler scheduler;

...
scheduler.standby();
...
scheduler.start();

Upvotes: 0

user1039758
user1039758

Reputation:

We can use the stdScheduler.pauseJob(JobKey jobKey) method to reduce the number of loops mentioned in the code above

Upvotes: 5

Hemant Metalia
Hemant Metalia

Reputation: 30698

I got it work by use of following code

stdScheduler is a scheduleFactoryBean

 String groupnames[] = stdScheduler.getJobGroupNames();
 for (String groupName : groupnames) {
     String[] jobNames = stdScheduler.getJobNames(groupName);
     for (String jobName : jobNames) {
            if (jobName.equals("jobName")) {
                    stdScheduler.pauseJob(jobName, groupName);
            }
     }
 }          

Upvotes: 6

Anthony Accioly
Anthony Accioly

Reputation: 22481

Inject your SchedulerFactoryBean. Use it's getScheduler method to obtain a quartz Scheduler and use rescheduleJob or other methods from quartz API to perform your task.

Upvotes: 7

Related Questions