在 Java 中使用 Quartz 运行两个作业
我的 Quartz 编码如下,第一个作业完美运行:
JobDetail jd = null;
CronTrigger ct = null;
jd = new JobDetail("Job1", "Group1", Job1.class);
ct = new CronTrigger("cronTrigger1","Group1","0/5 * * * * ?");
scheduler.scheduleJob(jd, ct);
jd = new JobDetail("Job2", "Group2", Job2.class);
ct = new CronTrigger("cronTrigger2","Group2","0/20 * * * * ?");
scheduler.scheduleJob(jd, ct);
但我发现 Job2(与 Job1 完全独立的作业)不会执行。
调度程序是使用 Java 中的侦听器启动的。我也尝试过使用 Scheduler.addJob(jd, true);但没有任何改变。我在 Windows 7 上通过 JVM 运行 Java。
I have Quartz coded as follows and the first job runs perfectly:
JobDetail jd = null;
CronTrigger ct = null;
jd = new JobDetail("Job1", "Group1", Job1.class);
ct = new CronTrigger("cronTrigger1","Group1","0/5 * * * * ?");
scheduler.scheduleJob(jd, ct);
jd = new JobDetail("Job2", "Group2", Job2.class);
ct = new CronTrigger("cronTrigger2","Group2","0/20 * * * * ?");
scheduler.scheduleJob(jd, ct);
But I'm finding that Job2, which is a completely separate job to Job1, will not execute.
The scheduler is started using a listener in Java. I've also tried using scheduler.addJob(jd, true); but nothing changes. I'm running Java through a JVM on windows 7.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你怎么知道作业没有运行?如果将
Job1.class
替换为Job2.class
,它仍然会失败吗?当您交换它们添加到调度程序的顺序时,或者只保留Job2
时?或者,如果您精简Job2
以仅将消息打印到控制台?我怀疑 Job2 执行因异常而终止。
How do you know the job does not run? If you substitute
Job1.class
forJob2.class
, does it still fail? When you swap order in which they're added to scheduler, or only leaveJob2
? Or if you strip downJob2
to only print a message to console?I suspect
Job2
execution dies with an exception.