Search code examples
javaspringcron

Cron expression for 1st and 3rd Sundays for @Scheduled


I know how I can schedule a job for first Sunday of the months thanks to answer here.

"0 0 10 1-7 * SUN"

But I want to trigger the job on first & third Sundays.

Also can it be a one liner?


Solution

  • If you want to follow the same pattern then

    So as 1 st Sunday will always be in day 1 to 7 and likewise 2nd Sunday 8-14 and 3rd Sunday 15-21 and 4th one 22-28

    "0 0 10 1-7 * SUN"
    "0 0 10 15-21 * SUN"
    

    or

    "0 0 10 1-7,15-21 * SUN"