I have a following problem with Quartz JobDataMap. I expect that when using simple Quartz Job and passing not-primitive object (e.g. instance of StringBuilder) into JobDateMap, method execute (from my job) should be always invoked with different copy of objected I put. Unfortunately I always get instance of object I put into JobDateMap (like it would be a StatefulJob).
In bellow example I expect to get single ‘*’ in every invocation while I get one more ‘*’ every time.
public class MyJob implements Job {
public static void main(String[] args) throws SchedulerException {
SchedulerFactory schedFact = new StdSchedulerFactory();
Scheduler sched = schedFact.getScheduler();
JobDetail jobDetail = new JobDetail("job", Scheduler.DEFAULT_GROUP, MyJob.class);
jobDetail.getJobDataMap().put("param", new StringBuilder());
Trigger trigger = TriggerUtils.makeImmediateTrigger("trigger", 10, 100);
trigger.setGroup(Scheduler.DEFAULT_GROUP);
sched.scheduleJob(jobDetail, trigger);
sched.start();
try {
Thread.sleep(1000L);
} catch (Exception e) {}
sched.shutdown(true);
}
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
StringBuilder sb = (StringBuilder) context.getMergedJobDataMap().get("param");
sb.append("*");
System.out.println(sb.toString());
}
}
I think, I’m missing something about how Quartz is working. Anybody knows what?
source: http://www.quartz-scheduler.org/documentation/2.3.1-SNAPSHOT/best-practices.html#jobdatamap-tips