-1

I have a job to execute on Saturday and Sunday, but not on weekdays. This is how I schedule it:

myTriggerBuilder.withSchedule(cronSchedule("0 0 0 * * ?")).build();

This will run at 00:00:00 server time each day. However, I would like to make it work only on Saturday and Sunday, however, in American calendars Saturday is the end of the week and Sunday is the start of the week. I have been searching the docs for an example or description which explains how can I specify certain days of the week rather than intervals, but the docs either does not provide that information, or I have missed it. I have tried it this way:

myTriggerBuilder.withSchedule(cronSchedule("0 0 0 * * SAT,SUN")).build();

However, the whole thing crashed:

java.lang.RuntimeException: CronExpression '0 0 0 * * SAT,SUN' is invalid.

Is there a way to express what I want, that is, to tell the scheduler which days of the week I intend to run the job?

Molly
  • 1,887
  • 3
  • 17
  • 34
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175

2 Answers2

1

you can try expression like (for example you want to start 8:05 Sunday 0 for Sunday and 6 for Saturday)

5 8 * * 0,6

You can check this link

https://crontab.guru/every-weekend

Mathieu
  • 8,840
  • 7
  • 32
  • 45
vivekdubey
  • 484
  • 2
  • 7
1

Can you please try this?

0 0 0 ? * SUN,SAT *

Refer: This

Ganesa Vijayakumar
  • 2,422
  • 5
  • 28
  • 41