gpt4 book ai didi

Java Quartz - cron 表达式

转载 作者:行者123 更新时间:2023-12-02 00:10:20 25 4
gpt4 key购买 nike

我有一个用 Java 编写的报告创建程序,需要每周一运行,我使用 Quartz 来进行调度部分。诀窍是,需要生成的报告数量各不相同;取决于星期一是该月的第一天,还是随后的星期一。

为了实现这一目标,我所做的是为每月的每个星期一创建一个触发器,第一个星期一指向特定的工作类别,而其余的星期一(触发器)指向另一个工作类别。

        .withIdentity("trigger1", "group1")
.withSchedule(cronSchedule("0 1 0 ? 1/1 MON#1 *"))
.build();

.withIdentity("trigger2", "group1")
.withSchedule(cronSchedule("0 1 0 ? 1/1 MON#2 *"))
.build();

依此类推,直到我到达

        .withIdentity("trigger5", "group1")
.withSchedule(cronSchedule("0 1 0 ? 1/1 MON#5 *"))
.build();

它到达了 MON#5,因为一个月可能有 5 个星期一;就像今年十月。这很好,它有效(我认为),但我的问题是这样的。有没有一种方法可以合并我的 cron 计划,以便我在接下来的星期一只需要一个触发器?类似的东西;

        .withSchedule(cronSchedule("0 1 0 ? 1/1 MON#2,MON#3,MON#4,MON#5 *"))

如果有的话请赐教。如果我在编程中遗漏了某些东西,或者迷宫中存在未知的页面(这是引导我找到真相的网络),请为我指出正确的方向。

非常感谢您的善意之言。谢谢

p.s:我包含了一个 cron 标签,尽管它说它适用于 UNIX 计算机。我相信 Quartz cron 和 Unix cron 之间几乎没有区别。如果有的话请告诉一下。

最佳答案

您的问题似乎没有正式的解决方案。

这里引用了 Quartz 2.0 documentation :

The '#' character is allowed for the day-of-week field. This character is used to specify "the nth" XXX day of the month. For example, the value of "6#3" in the day-of-week field means the third Friday of the month (day 6 = Friday and "#3" = the 3rd one in the month). Other examples: "2#1" = the first Monday of the month and "4#5" = the fifth Wednesday of the month. Note that if you specify "#5" and there is not 5 of the given day-of-week in the month, then no firing will occur that month. If the '#' character is used, there can only be one expression in the day-of-week field ("3#1,6#3" is not valid, since there are two expressions).

this. 上也存在一个 Unresolved 错误

关于Java Quartz - cron 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12950186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com