标签:注解 固定 了解 auth rip image ica http led
@Scheduled为设置定时任务的注解。
参数常用的为两种:
基于注解设置定时任务
1.创建定时任务处理类TimedTask
package com.lw.coodytask.scheduled; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.time.LocalDateTime; /** * @Classname TimedTask * @Description 定时任务 * @Author lw * @Date 2019-12-20 16:43 */ @EnableScheduling @Component public class TimedTask { @Scheduled(fixedRate = 5000) public void task_1(){ System.out.println("定时任务1:" + LocalDateTime.now()); } @Scheduled(cron = "0/5 * * * * ?") public void task_2(){ System.out.println("定时任务2:" + LocalDateTime.now()); } }
2.启动CoodyTaskApplication服务
package com.lw.coodytask; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class CoodyTaskApplication { public static void main(String[] args) { SpringApplication.run(CoodyTaskApplication.class, args); } }
3.效果
标签:注解 固定 了解 auth rip image ica http led
原文地址:https://www.cnblogs.com/lwcode6/p/12074414.html