roynalnaruto
roynalnaruto

Reputation: 339

Spring Scheduling with calculated initialDelay

I am running a method in my application, with a fixed delay of a week. But I need the method to run for the first time only at 12 midnight on Sunday. I can get the date-time using the Calendar util, but how do I set that variable in to the initialDelay parameter?

@Scheduled(initialDelay = 1000, fixedDelay = 1000*60*60*24*7)
public void updateLeaderboard() {

    System.out.println("updating leaderboard");

}

Upvotes: 0

Views: 365

Answers (1)

Ori Dar
Ori Dar

Reputation: 19000

You will have to use a cron expression for that:

0 0 0 * * sun

or more specifically:

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

Upvotes: 1

Related Questions