padmini
padmini

Reputation: 11

Quartz scheduler does not trigger at given time

I have a program which reschedules jobs for one hour. Sometimes it triggers at the given time, and sometimes it misses the trigger time.

There is no exception or error in the logs. How can I make the trigger work at the given time?

Any help is invited. My code is as follows:

StdSchedulerFactory sf = new StdSchedulerFactory();
Scheduler clusteredScheduler = sf.getScheduler();
Trigger tg = clusteredScheduler.getTrigger("myjob", "group1");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR, schedulerConstants.HOUR);
Trigger tg = scheduler.getTrigger(
    schedulerConstants.START_PREPARE_SEARCH_CONSUMER_JOB_NAME,
    schedulerConstants.JOB_GROUP_NAME);
((CronTrigger) tg).setCronExpression(
    "0 " + cal.get(Calendar.MINUTE) + " " + cal.get(Calendar.HOUR_OF_DAY) + " * * ?");
clusteredScheduler.rescheduleJob("myjob", "group1", tg);

This is my full code. Sometimes the scheduler will get stuck and remain unresponsive. There is no error or exception in logs. I have tried increasing the number of threads in the thread pool, and the problem persists.

Upvotes: 1

Views: 2452

Answers (1)

Art Licis
Art Licis

Reputation: 3679

Your code is insufficient to help identifying your problem. You only show the code part where you update an existing trigger (scheduler.getTrigger(...)). You might have forgot to reschedule the Job after you've updated the trigger: Scheduler#rescheduleJob. Also, be careful in reusing same trigger with multiple jobs.

Your trigger is daily, on a specific time (more specifically - current time taken, and most likely one hour added). Have you tried running the system in more frequent trigger, and seeing what happens (unless you don't have a better way how to automate this test)?

Just in case - if you are experimenting with time shifting on your dev. machine to see if it runs the job with the specified intervals, it might actually not work as you expect.

Upvotes: 2

Related Questions