简体   繁体   中英

Quartz scheduler how to pass the results from job execution to display it in UI

Im using java quartz scheduler for scheduling a job once.There is a Executor class which implement job and we override the execute method for the job execution. The job execution works fine. But I want to send the result of the job execution to class that invoked the Executor class. Not sure how to do the same. The result returned is an Object of an internal class.The version of quartz im using is 1.6.6

Servlet code. schedule method of servlet

jDetail = new JobDetail(sched.getProjectName(), Executor.class);
                jDetail.getJobDataMap().put("usrName",schedule.getUsername()); 
                jDetail.getJobDataMap().put("prjName", sched.getProjectName());
                jDetail.getJobDataMap().put("srcSchema",srcData); 
                jDetail.getJobDataMap().put("tgtSchema",targetData); 
                jDetail.getJobDataMap().put("mapDetails",mapData); 
 cronTrigger = new CronTrigger(sched.getUsername(), sched.getProjectName(), sched.getCronExpression()) ;
  SchedulerFactory sf=new StdSchedulerFactory();
  Scheduler sched=sf.getScheduler();
  sched.scheduleJob(jDetail, cronTrigger);
  sched.start();

I have checked in google and they have specified to set the result in JobExecutionContext.setResult(). But Im not sure how to retrive the result.

Any help on this is much appreciated. Thanks in Advance.

You can write your result in your Job.execute method:

public void execute(JobExecutionContext context) throws JobExecutionException {
  context.setResult("TestResult");
}

and you can read it:

for(JobExecutionContext jobContext : scheduler.getCurrentlyExecutingJobs()){
  jobContext.getResult();
}

But why you should need it there? :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM