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());
}