1、定时任务-相关代码
@Component @EnableScheduling public class PrintTask { @Value("${task.switch}") private String taskSwitch; //统计器 private volatile int count = 0; //定时任务 @Scheduled(cron = "*/5 * * * * ?") public void print() { if (taskSwitch.equals("open") ) { System.out.println("task"+count++); } } }
2、参数配置
task.switch=open
3、执行结果
task0 task1 task2