EN
Spring @Scheduled every 5 min practical example
1 points
Quick solution:
xxxxxxxxxx
1
import lombok.extern.slf4j.Slf4j;
2
import org.springframework.scheduling.annotation.Scheduled;
3
import org.springframework.stereotype.Service;
4
5
import java.time.LocalDateTime;
6
7
8
9
public class CronExampleService {
10
11
cron = "0 0/5 * * * *") (
12
public void eachFiveMinutes() {
13
log.info("test info " + LocalDateTime.now());
14
}
15
}
Output:
xxxxxxxxxx
1
2021-07-14 05:15:00.030 INFO 21716 --- [ scheduling-1] example.service.CronExampleService : test info 2021-07-14T05:15:00.026327
2
2021-07-14 05:20:00.006 INFO 21716 --- [ scheduling-1] example.service.CronExampleService : test info 2021-07-14T05:20:00.006950
3
2021-07-14 05:25:00.008 INFO 21716 --- [ scheduling-1] example.service.CronExampleService : test info 2021-07-14T05:25:00.008971