Reputation: 433
I use Quartz 2 to create a Interval in Java.
Now i want to pass the Object obj1 from the Updater to the UpdateJob. How can i make this ?
Interval.java/Updater :
public class Interval {
public static void Updater( Object obj1 ) throws SchedulerException {
JobDetail job = newJob(UpdateJob.class).withIdentity("UpdateJob", "Group1").build();
Trigger trigger = newTrigger().withIdentity("UpdateTrigger", "Group1")
.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever()).build();
Scheduler sched = new StdSchedulerFactory().getScheduler();
sched.scheduleJob(job, trigger);
sched.start();
}
}
UpdateJob.java :
public class UpdateJob implements Job {
public void execute(JobExecutionContext context)
throws JobExecutionException {
//obj1 jobs
}
}
Upvotes: 1
Views: 1953
Reputation: 98
You can use datamap
job.getJobDataMap().put("key",obj1);
and then get it from job:
JobDataMap data = _context.getJobDetail().getJobDataMap();
Object o = data.get("key");
Upvotes: 2