上午 8 点到晚上 8 点之间按指定的时间间隔执行 4 次 cron 作业
我需要每天运行“x”次工作。工作时间为上午 8 点至晚上 8 点之间的每个(称“y”小时)。 我阅读了 cron 之间的文档,无法弄清楚如何放置“时间之间”。任何建议或好的教程都应该非常有帮助。我可以弄清楚这么多。
在教程中找到了这个。 要求。
SimpleTrigger simpleTrigger = new SimpleTrigger("simpleTrigger", "triggerGroup-s1");
simpleTrigger.setStartTime(d);
simpleTrigger.setRepeatInterval(1000*60*60*24);
simpleTrigger.setRepeatCount(15);
simpleTrigger.setEndTime(new Date(ctime + 60000L));
simpleTrigger.setPriority(10);
scheduler.scheduleJob(jobDetail, simpleTrigger);
scheduler.start();
我相信这将满足我如何修改表达式以达到我的目的的
i need to run a job 'x' times a day. job timing is every (say 'y' hours) between 8am and 8pm.
i read the documentation of cron between could not figure out how to place the "between times". any suggestion or a good tutorial should be really helpful.i could figure out this much.
Found this in a tutorial. I believe this will serve the requierment
SimpleTrigger simpleTrigger = new SimpleTrigger("simpleTrigger", "triggerGroup-s1");
simpleTrigger.setStartTime(d);
simpleTrigger.setRepeatInterval(1000*60*60*24);
simpleTrigger.setRepeatCount(15);
simpleTrigger.setEndTime(new Date(ctime + 60000L));
simpleTrigger.setPriority(10);
scheduler.scheduleJob(jobDetail, simpleTrigger);
scheduler.start();
how could i modify the expression to serve my purpose.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的示例中有一个
*
,您需要在其中输入开始/结束时间:将
y
替换为您想要的运行之间的小时数应该没问题。如果你有一些奇怪的时间,比如“两次跑步之间有 1 小时 15 分钟”,这将是一件痛苦的事情 - 可能只是更容易计算每次并明确输入它。You have a
*
in your example where you need to put the start/end hours:Where you replace
y
with the number of hours you want between runs should be fine. If you have some strange time like "1 hour and 15 minutes between runs", it's going to be a pain - probably just easier to calculate each time and enter it explicitly.我不知道你能用 cron 表达式来表达这一点。
但是,您可以使用多个 Quartz 触发器来实现此目的。
I don't know you can express this in cron expression.
However, you can use multiple Quartz triggers to serve this purpose.