quartz-scheduler / quartz

Code for Quartz Scheduler
http://www.quartz-scheduler.org
Apache License 2.0
6.31k stars 1.94k forks source link

Quartz Scheduler Executes Multiple Times Despite Fixed Interval and Date Configuration #1227

Open Git-Mani opened 1 month ago

Git-Mani commented 1 month ago

We have encountered an issue with the Quartz Scheduler where jobs are executing multiple times even after being configured for a fixed time interval and specific date. This behavior is causing duplicate job executions and potential data inconsistencies.

Environment:

Scheduler Configuration:

Here are the properties used to instantiate the SchedulerFactoryBean:

properties.setProperty("org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread", "true");
properties.setProperty("org.quartz.jobStore.class", "com.novemberain.quartz.mongodb.MongoDBJobStore");
properties.setProperty("org.quartz.jobStore.mongoUri", "mongoUri");
properties.setProperty("org.quartz.jobStore.dbName", "mongoDatabase");
properties.setProperty("org.quartz.jobStore.collectionPrefix", "quartz-entry");
properties.setProperty("org.quartz.threadPool.threadCount", "5");

Trigger Configuration:

The trigger is configured as follows:

Date startDate = new SimpleDateFormat("yyyy-MM-dd").parse(req.getSchedule().getStartDate());
Date endDate = new SimpleDateFormat("yyyy-MM-dd").parse(req.getSchedule().getEndDate());

SimpleTrigger cronTrigger = TriggerBuilder.newTrigger()
        .withIdentity("trigger", req.getId() + "_" + req.getName())
        .startAt(startDate)
        .endAt(endDate)
        .withSchedule(simpleSchedule()
                .withIntervalInMinutes(req.getSchedule().getIntervalMinutes())
                .withMisfireHandlingInstructionFireNow()
                .repeatForever())
        .build();

Expected Behavior: The job should execute only once according to the specified schedule, without any duplicate executions.

Actual Behavior: Jobs are executing multiple times.

The issue occurs infrequently and has not been observed in the local environment.

Any assistance in identifying the root cause of this issue or advice on debugging and preventing these rare occurrences of multiple executions would be greatly appreciated. If anyone has encountered similar behavior with Quartz Scheduler or can suggest troubleshooting steps, please share your insights.

jhouserizer commented 1 month ago

Hi! Not aware of any similar problem reports, and thinking what could cause the issue makes me think of transaction isolation issues as a likely culprit. Then looking at your config, you have this: properties.setProperty("org.quartz.jobStore.class", "com.novemberain.quartz.mongodb.MongoDBJobStore"); -- which means the thing you have doing the work around transactions is not something that is part of Quartz.