Reputation: 1
We are running one schedule using Quartz and getting the updated data from table in the executeinternal method, but how to access that java object from main method.
Here is the code:
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
JobDetail jobDetail = new JobDetail("SlaTime", "SlaTimeGroup",
SlaUptimeImpl.class);
CronTrigger cronTrigger = new CronTrigger("SlaTrigger", "SlaGroup",
"0/10 * 0-23 ? * *");
scheduler.scheduleJob(jobDetail, cronTrigger);
scheduler.start();
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Here we are executing the query in this SlaUptimeImpl
class but not able to get the return data here because am executing the query in ExecuteInternal
Method which have return type as void
.
anyone help me in this issue.
Thanks in advance, Mahesh
Upvotes: 0
Views: 2024
Reputation: 974
You can provide a data map to your job, thanks to JobBuilder#usingDataMap(). I think you could put an "observer" into this map, retrieve the observer at job execution, and notify it about the result.
While scheduling your job:
JobDataMap map = new JobDataMap();
map.put("myObserver", new MyObserver());
JobDetail jobDetail = JobBuilder.newJob(SlaUptimeImpl.class).withIdentity("SlaTime", "SlaTimeGroup").usingJobData(map).build();
And in your job:
public void execute(final JobExecutionContext context) throws JobExecutionException {
...
((MyObserver) context.getJobDetail().getJobDataMap().get("myObserver")).notify(result);
}
Upvotes: 1