Issue with Quartz scheduler – its running twice

Recently I integrated quartz job scheduling to spring boot application and noticed a single thread is triggered twice after the scheduler is instantiated.

The simplest way I found to fix the issue is to use a simple lock. However I’m not sure if its the proper solution.

public void execute(JobExecutionContext context) throws JobExecutionException {
logger.info(“Job ** {} ** fired @ {}”, context.getJobDetail().getKey().getName(),                   context.getFireTime());

       synchronized (lock) {
           try {
                    methodToBeCalled( context);
           } catch (UnknownHostException e) {
                e.printStackTrace();
           }
        }
       logger.info(“Next job scheduled @ {}”, context.getNextFireTime());
}

 

 

About buminda

buminda.com
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment