2
votes

I am using Quartz Scheduler (v2.2.1) in some Java WARs and I am having some trouble while recovering from database errors. The WARs are deployed in JBOSS AS 7.1.

In the initialization of the WAR, I start two schedulers: the first one configured with JobStoreTX as clustered (the WARs are deployed in a cluster) and the second one, configured with RAMJobStore in order to monitor some server specific settings.

The RAM Scheduler also includes a Job which monitors a table from a MySQL database. In case of error, it would be desirable to keep the Quartz jobs firing, but the fact is sometimes the Scheduler is frozen and these jobs are not fired.

For instance, I used the following method in my tests, with no luck re-instantianting the scheduler:

/**
 * Resets all scheduled jobs.
 */
public void reset(final long currentTime) {

    try {
        final StdSchedulerFactory schedFactory = new StdSchedulerFactory();
        schedFactory.initialize("quartz.properties");
        Scheduler myScheduler = schedFactory.getScheduler();

        if (myScheduler != null) {                
            myScheduler.clear();                
            myScheduler.shutdown(); --> HERE, THE THREAD IS LOCKED !!!                
            myScheduler = null;
        }

        myScheduler = schedFactory.getScheduler();
        loadJobs(myScheduler);
        myScheduler.start();
        //myScheduler.startDelayed(10);                        

    } catch (SchedulerException e) {
        LOG.error("Scheduler error !!!");
    }
}

Which is the proper method to restart a Quartz Scheduler?

Thanks in advance

UPDATE 1

As the Scheduler object seems to be the same...I modified the method, with no luck, re-instantiating the StdSchedulerFactory and the Scheduler before calling shutdown.

Could you provide any functional example?

Thanks

2

2 Answers

0
votes

saying the scheduler was frozen would mean the API has a huge bug. Could you please provide stack trace or any errors thrown in the case you are mentioning.

based on my experience scheduler object returned will be same as many times you call

schedFactory.getScheduler();

you may need to clean up old jobs, de-reference them or stop them.

Correct steps would be

-1- fetch the scheduler object

-2- stop the scheduler by calling to scheduler.shutdown();

-3- load the jobs again and start the scheduler

0
votes

Use quartz JMX options and that MBean have operations like start() , shutdown() and clear() etc. making lives real simpler.