一.创建定时任务类,类上添加注解@EnableScheduling,任务方法上添加@Scheduled(cron = “0/50 * * * * ?”)
@Component
@EnableScheduling
public class ScheduledTask {
@Autowired
private RabbitService rabbitService;
/**
* 每天8点执行 提醒就诊
*/
//@Scheduled(cron = "0 0 8 * * ?")
@Scheduled(cron = "0/50 * * * * ?")//50秒触发一次
public void task1() {
//任务内容
System.out.println(new Date().toLocaleString());
}
}
cron表达式控制定时任务触发的时间
通过不同的cron来指定触发时间