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