Java – Firing Quartz jobs manually

javaquartz-scheduler

We have several Quartz jobs configured in our application. During development, we leave the quartz scheduler in standby – however, we sometimes want to start a job manually (for development purposes). If I call fireTrigger, it tells me I need to start the scheduler. However, if I start the scheduler, it will also immediately schedule all the other jobs, which is not what I want (since they may trigger while I'm debugging the manually fired job).

I could pause all triggers when I start the scheduler, but then I have to deal with misfire instructions etc.

Is there a simple way to fire off a job manually without having to deal with pausing and misfires (i.e. a fireTrigger which works even if the scheduler is in standby)?

Best Answer

this is the loop you will require to fire the job manually:

SchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
Scheduler scheduler = stdSchedulerFactory.getScheduler();

// loop jobs by group
for (String groupName : scheduler.getJobGroupNames()) {
    // get jobkey
    for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
        String jobName = jobKey.getName();
        String jobGroup = jobKey.getGroup();
        scheduler.triggerJob(jobName, jobGroup);
    }
}
Related Topic