Colin
Colin

Reputation: 11

Quartz scheduleJob Exceptions

Ok, so here I've got a Quartz(version 2.2.1) job that should instantiate two other jobs, create and add two triggers for each job, and add both jobs to the scheduler, deleting them after a set interval that's passed in through the JobDataMap.

When this job is run by the scheduler, it throws the following exception:

org.quartz.JobPersistenceException: The job (DEFAULT.countdown15, countdownGroup) referenced by the trigger does not exist.

The exception is thrown at line 71:

sched.scheduleJob(countdown15Trigger2);

I couldn't figure out why the job doesn't exist at that point, since it should have been created by the earlier newJob call and added to the scheduler by line 70:

sched.scheduleJob(countdown15, countdown15Trigger1);

So, I temporarily commented out that line and attempted to run the program again, whereupon I got this exception at line 72:

line 72:

sched.scheduleJob(countdown60, countdown60Trigger1);

exception:

org.quartz.SchedulerException: Trigger does not reference given job!

Ok, so now I've got two scheduleJob calls throwing two different exceptions, even though as far as I can tell I'm following the correct syntax. But the first scheduleJob call must be working correctly, because the exceptions are occurring later in the code, so for now I'll comment out all the other scheduleJob calls and see what happens.

And then I get this error at line 70, the first and now only scheduleJob call:

org.quartz.ObjectAlreadyExistsException: Unable to store Job : 'countdownGroup.countdown15', because one already exists with this identification.

I don't really know where to go from here, so here's the complete code for the top level job. Any ideas?

public class ShowClockJob implements Job {

public ShowClockJob() {}

@Override
public void execute(JobExecutionContext context)
    throws JobExecutionException {
    JobDataMap dm = context.getJobDetail().getJobDataMap();
    int min = dm.getInt("min");  //show's runtime in minutes
    int ms = min * 60000;  //convert the runtime in minutes to millisec
    Scheduler sched = context.getScheduler();
    JobDetail countdown15 = newJob(CountdownJob15.class)
            .withIdentity(jobKey("countdown15", "countdownGroup"))
            .build();

    JobDetail countdown60 = newJob(CountdownJob60.class)
            .withIdentity("countdown60", "countdownGroup")
            .build();

    Trigger countdown15Trigger1 = newTrigger()
            .withIdentity("countdown15Trigger1", "countdownGroup")
            .withSchedule(cronSchedule("45 5 * * * ?")
                .withMisfireHandlingInstructionDoNothing())
            .forJob(jobKey("countdown15", "countdownGroup"))
            .build();

    Trigger countdown15Trigger2 = newTrigger()
            .withIdentity("countdown15Trigger2", "countdownGroup")
            .withSchedule(cronSchedule("55 19,32,46 * * * ?")
                .withMisfireHandlingInstructionDoNothing())
            .forJob(jobKey("countdown15, countdownGroup"))
            .build();

    Trigger countdown60Trigger1 = newTrigger()
            .withIdentity("countdown60Trigger1", "countdownGroup")
            .withSchedule(cronSchedule("0 17,29,44 * * * ?")
                .withMisfireHandlingInstructionDoNothing())
            .forJob(jobKey("countdown60, countdownGroup"))
            .build();

    Trigger countdown60Trigger2 = newTrigger()
            .withIdentity("countdown60Trigger2", "countdownGroup")
            .withSchedule(cronSchedule("50 57 * * * ?")
                .withMisfireHandlingInstructionDoNothing())
            .forJob("countdown60, countdownGroup")
            .build();
    try {
        sched.scheduleJob(countdown15, countdown15Trigger1);
        sched.scheduleJob(countdown15Trigger2);
        sched.scheduleJob(countdown60, countdown60Trigger1);
        sched.scheduleJob(countdown60Trigger2);

        Thread.sleep(ms);  //sleep for the length of the showtime, 

        //...then shut down the countdown jobs
        sched.deleteJob(jobKey("countdown15","countdownGroup"));
        sched.deleteJob(jobKey("countdown60","countdownGroup"));
    } catch (SchedulerException | InterruptedException ex) {
        Logger.getLogger(ShowClockJob.class.getName()).log(Level.SEVERE, null, ex);
    }

}

}

Upvotes: 0

Views: 5187

Answers (1)

Colin
Colin

Reputation: 11

Turns out it was a simple syntax error. In all but the first trigger creation blocks, at the forJob method, I left out the middle two parenthesis that seperated the jobKey and jobGroup into two strings.

So this:

forJob("countdown60, countdownGroup");

Should have been this:

forJob("countdown60", "countdownGroup");

Upvotes: 1

Related Questions