1、添加依赖
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-test
test
2、创建任务类
@Component
public class ScheduledService {
@Scheduled(cron = “0/5 * * * * *”)
public void scheduled(){
log.info("=>>>>>使用cron {}",System.currentTimeMillis());
}
@Scheduled(fixedRate = 5000)
public void scheduled1() {
log.info("=>>>>>使用fixedRate{}", System.currentTimeMillis());
}
@Scheduled(fixedDelay = 5000)
public void scheduled2() {
log.info("=====>>>>>fixedDelay{}",System.currentTimeMillis());
}
}
springboot中使用注解实现定时任务
最新推荐文章于 2024-05-10 13:22:41 发布