0

I am working on a quartz scheduler. I have created a class(com.test.job.MyClass) that implements Job MyClass contains some dynamic values which pass in DataMap while scheduling. based on datamap value, i need to invoke the rest API by passing this data map value.

So in my DB, I defined job having className, jobName, groupName and operationValue. I have defined multiple entries in DB having

Like JOB-1 is

jobClassName= com.test.job.MyClass
jobName=TEST1
groupName =group
operationValue =ADD

Like JOB-2 is

jobClassName= com.test.job.MyClass
jobName=TEST2
groupName =group
operationValue =ADD

I am trying to schedule these 2 jobs having same Cron expression. but only the TEST1 job is executing. Test2 is not. even the jobName is different

Scheduler scheduler = scheduleFactory.getScheduler();
        try {
            Class<? extends Job> jobClassName = (Class<? extends Job>) Class.forName(className);
            JobDetail jobDetails = JobBuilder.newJob(jobClassName).withIdentity(jobName, groupName).build();
            putIntoDataMap(job, jobDetails.getJobDataMap(), user);
            CronTrigger trigger = newTrigger().withIdentity(jobName, groupName)
                    .withSchedule(cronSchedule(cronExpression).inTimeZone("Asia/Kolkata")).build();

            scheduler.scheduleJob(jobDetails, trigger);
        } catch (SchedulerException | ClassNotFoundException ex) {
            throw new CredityRuntimeException(CredityErrorCodes.INVALID_TRIGGER.name(), ex);
        }

in the implemented class, I can see ADD operation, so it means only TEST1 was run. I expect both should run.

public class MyClass implements Job {

@Override
    public void execute(JobExecutionContext context) throws JobExecutionException 
    {
        .....
         String operationValue=jobDataMap.get("Operation");
    }
}
Musaddique S
  • 1,539
  • 2
  • 15
  • 36

1 Answers1

0

Very strange. You may want to use QuartzDesk (I am biased here) or some other alternative Quartz management GUI tool to:

(1) connect to your Quartz instance and check the registered jobs and triggers. In your case, you should see two jobs TEST1 and TEST2.

(2) try to manually execute the registered jobs to see if your jobs can be invoked.

Note: The free QuartzDesk Lite Edition should be entirely sufficient and help you quickly identify the issue.

One thing to be aware of is the job durability flag. Non-durable Quartz jobs are automatically discarded by Quartz when there are no associated triggers that are expected to fire the job in the future. You did not include your cron expressions for TEST1 and TEST2 so you may want to call storeDurably when building your job details just in case...

Jan Moravec
  • 1,808
  • 1
  • 15
  • 18
  • I tried but didn't see TEST 1 and TEST2 at the same time. if I schedule for different time, I can see – Musaddique S Jun 07 '20 at 18:12
  • If you can share your app, or a simplified version of it that exhibits the issue, I will look into it and find out what is going on. – Jan Moravec Jun 09 '20 at 16:20