3
votes

I am using Spring schedule. I configured the following Cron expression to run my task every Tuesday night at 9pm,

"0 0 21 * * TUE"

However, I am getting the following exception when am starting the application

Encountered invalid @Scheduled method 'runSchduler': Cron expression must consist of 6 fields

Is my Spring Cron expression wrong?

3

3 Answers

3
votes

Is my Spring Cron expression configured, to run every Tuesday night at 9 wrong?

Yes :)


But try,

0 0 21 ? * TUE

Or with the Spring annotation:

@Scheduled(cron = "0 0 21 * * TUE")

The following is a really handy website for creating Cron expressions.

http://www.cronmaker.com/ Take note: Just remove the last element from the created expression to use it with Spring scheduling.

And a nice way to verify it in Natural Language here

0
votes

Looks like you have a field too much?

Just generated this based on your criteria of Tuesdays at 9PM "0 21 * * 2"

0
votes

Cron Expression for Everyday Tuesday Midnight 9 PM

0 0 21 ? * TUE

cleck below cron with zone example

  @Component
    public class SpringScheduling {    

        @Scheduled(cron = "0 0 21 ? * TUE",zone="Asia/Calcutta")
        public void trackScheduling() {

              System.out.println("Scheduled task running");

        }
    }