简体   繁体   English

安排 Quartz 作业并在启动时运行

[英]Schedule Quartz job and run in startup

I defined a job with Quartz that calls a web service.我用 Quartz 定义了一个调用 Web 服务的作业。 I have a trigger with Cron expression which run every 50 minutes as 0 0/50 * ? * * *我有一个带有 Cron 表达式的触发器,它每 50 分钟运行一次0 0/50 * ? * * * 0 0/50 * ? * * * . 0 0/50 * ? * * * I have a requirement that execute the job in startup application and after that every 50 minutes.我有一个要求在启动应用程序中执行该作业,之后每 50 分钟执行一次。

the job factory is:工作工厂是:

            Trigger trigger = newTrigger().withIdentity(name, "our.trigger")
                                          .withSchedule(CronScheduleBuilder.cronSchedule("0 
                                              0/50 * ? * * *")).startNow().build();
            JobDetail jobDetail = newJob(jobClass).withIdentity(name, "our.job").build();
            Set<Trigger> triggers = new HashSet<>();
            triggers.add(trigger);
            stdScheduler.scheduleJob(jobDetail, triggers, true);
            stdScheduler.start();

How do I solve this issue?我该如何解决这个问题?

I solved the problem with the following code:我用以下代码解决了这个问题:

 Trigger startupTrigger = newTrigger().withIdentity(name+".startup", "trigger")
                            .withSchedule(SimpleScheduleBuilder.repeatSecondlyForTotalCount(1)).startNow().build();

Thanks for @biiyamn感谢@biiyamn

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

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