Home > database >  What is the CronTriggeringPolicy priority?
What is the CronTriggeringPolicy priority?

Time:07-08

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.

CodePudding user response:

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 0 * * ?") which will trigger at the first second of every hour allowing time for the daily log rollover to perform.

  • Related