简体   繁体   English

每3分钟执行一次Quartz Scheduler不返回values方法

[英]Quartz Scheduler not return values method executing in every 3 minutes

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. 我们正在使用Quartz运行一个调度,并在executeinternal方法中从表中获取更新的数据,但是如何从main方法访问该Java对象。

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 . 在这里,我们在此SlaUptimeImpl类中执行查询,但是由于在ExecuteInternal Method中执行查询(返回类型为void而无法在此处获取返回数据。

anyone help me in this issue. 任何人都可以帮助我解决这个问题。

Thanks in advance, Mahesh 在此先感谢,Mahesh

You can provide a data map to your job, thanks to JobBuilder#usingDataMap() . 由于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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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