0
votes

I'm trying to use Quartz in order to schedule jobs in a web app running on Glassfish. I'm using RAMJobStore. The problem is that sometimes, the job that was scheduled isn't being executed, even if it was scheduled in the past or the future. The amount of jobs are extremely low, a total of under 20 jobs scheduled at all times on the scheduler and a guaranteed maximum of 1 job running at the same time, so I presume the thread count is not an issue, I could set it to threadCount 1 and it would still work. The scheduler is also not being shut down before the servlet is being destroyed. So what can be the cause for some jobs not being run ?

StartupServlet

public void init()
    {
  try
        {
            scheduler = StdSchedulerFactory.getDefaultScheduler();
            scheduler.start();
            loadJobs();
        }
        catch (SchedulerException se)
        {
            se.printStackTrace();
        }
}

  @Override
    public void destroy()
    {
 try
        {
            scheduler.shutdown();
        }
        catch (SchedulerException se)
        {
            se.printStackTrace();
        }
    }

Scheduling a job

 JobDetail job = JobBuilder.newJob(ScheduledTransactionJob.class)
                                  .withIdentity(transaction.getId())
                                  .build();

        Trigger trigger = TriggerBuilder.newTrigger()
                                    .withIdentity(transaction.getId())
                                    .startAt(date)
                                    .build();
        try
        {
            scheduler.scheduleJob(job, trigger);
            dateFormat = new SimpleDateFormat("dd MMM yyyy, HH:mm:ss");
            String recurringTransactionTime = dateFormat.format(date);
            logger.info("Scheduled job for " + recurringTransactionTime);
        }
        catch (SchedulerException se)
        {
            se.printStackTrace();
        }

quartz.properties

#============================================================================
# Configure Main Scheduler Properties
#============================================================================

org.quartz.scheduler.skipUpdateCheck = true
org.quartz.scheduler.instanceName = AppScheduler
org.quartz.scheduler.instanceId = AUTO

#============================================================================
# Configure ThreadPool
#============================================================================

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 25
org.quartz.threadPool.threadPriority = 10

#============================================================================
# Configure JobStore
#============================================================================

org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
1

1 Answers

0
votes

Seems to be working now. Haven't ran into any more problems. Could've been a config issue, as I have moved the config file in /src/main/resources. Also try turning logging on in order to help with the debug:

log4j.logger.com.gargoylesoftware.htmlunit=DEBUG

We also added a JobTriggerListener to help with the logs:

private static class JobTriggerListener implements TriggerListener
    {
        private String name;

        public JobTriggerListener(String name)
        {
            this.name = name;
        }

        public String getName()
        {
            return name;
        }

        public void triggerComplete(Trigger trigger, JobExecutionContext context,
                                    Trigger.CompletedExecutionInstruction triggerInstructionCode)
        {

        }

        public void triggerFired(Trigger trigger, JobExecutionContext context)
        {

        }

        public void triggerMisfired(Trigger trigger)
        {
            logger.warn("Trigger misfired for trigger: " + trigger.getKey());
            try
            {
                logger.info("Available threads: " + scheduler.getCurrentlyExecutingJobs());
            }
            catch (SchedulerException ex)
            {
                logger.error("Could not get currently executing jobs.", ex);
            }
        }

        public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context)
        {
            return false;
        }
    }