Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring execute method every 15 minutes

Tags:

java

spring

cron

I tried to use cron expression from this site http://www.cronmaker.com/

@Scheduled(cron = "0 0/15 * 1/1 * ? *")
public void clearRps() {
            
}

But it throws: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'clearRps': Cron expression must consist of 6 fields (found 7 in "0 0/15 * 1/1 * ? *")

like image 803
Semyon Avatar asked Mar 02 '15 21:03

Semyon


People also ask

How do I run a cron job every 5 minutes in spring boot?

Spring boot provides @EnableScheduling and @Scheduled annotations, to schedule cron jobs in the spring boot application which runs periodically. Let's learn, how to use Spring boot @Scheduled annotation. Add @Scheduled annotations on methods that you want to schedule.

How does @scheduled work in spring?

We can turn any method in a Spring bean for scheduling by adding the @Scheduled annotation to it. The @Scheduled is a method-level annotation applied at runtime to mark the method to be scheduled. It takes one attribute from cron , fixedDelay , or fixedRate for specifying the schedule of execution in different formats.


1 Answers

Just use the following cron:

@Scheduled(cron = "0 0/15 * * * *")

Spring cron expression syntax slightly differs from unix cron expression. One immediate difference - it supports 1 less field (6 rather than 7).

like image 93
Rohit Jain Avatar answered Oct 12 '22 03:10

Rohit Jain