CrontriggeringPolicy的优先级是什么?

发布于 2025-02-13 16:48:54 字数 345 浏览 0 评论 0原文

我有一个每小时运行日志写作的CRON时间表。

@Scheduled(cron = "0 0 0 * * ?")

每小时,我都会使用log4j2的crontriggeringpolicy将日志滚动到前一天。

CronTriggeringPolicy schedule="0 0 0 * * ?"

目前,问题是,如果cron滚动日志的时间和离开日志的cron相同,

哪个是首先起作用的?

我想要它的工作方式是首先完成滚动,并编写新的日志。

在我的实验中,滚动是发生的第一件事,但我不知道这是巧合还是系统的意图。

I have a cron schedule that runs log writing every hour.

@Scheduled(cron = "0 0 0 * * ?")

And every hour I use Log4j2's CronTriggeringPolicy to roll the logs up to the previous day.

CronTriggeringPolicy schedule="0 0 0 * * ?"

At this time, the question is, if the time of cron rolling the log and cron leaving the log are the same,

Which one works first?

The way I want it to work is that the rolling is done first, and a new log is written.

In my experiments, rolling is the first thing that happens, but I don't know if it's a coincidence or what the system intended.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺渁∝ 2025-02-20 16:48:54

首先,@scheduled(cron =“ 0 0 0 * *?”)每天在00:00:00触发。小时时间表定义为@scheduled(cron =“ 0 0 * * *?”)

其次,@scheduled spring中的实现,crontriggeringpolicy log4j中的是完全独立的,并且是同一概念的无关实现,因此您所体验的内容很可能是巧合。

从小时开始,可以将确定的时间表的确定排序订购的一种方法可以将它们中的任何一个转移到一定量中,例如@scheduled(cron =“ 1 0 * * * * *?”)哪个会在哪个会触发的每小时的第一秒,可以使每日日志滚动执行时间。

First, @Scheduled(cron = "0 0 0 * * ?") triggers at 00:00:00 every day. The hourly schedule is defined as @Scheduled(cron = "0 0 * * * ?").

Second, the @Scheduled implementation in Spring and CronTriggeringPolicy in Log4j are completely separate and unrelated implementations of the same concept so what you experience is most likely a coincidence.

One way to achieve the determined ordering of schedules could be shifting either of them by some amount from the hour start, e.g. @Scheduled(cron = "1 0 * * * ?") which will trigger at the first second of every hour allowing time for the daily log rollover to perform.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文