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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2021-09-23
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-10
  • 2021-11-19
  • 2021-06-06
  • 2022-01-27
  • 2022-01-11
  • 2021-06-17
相关资源
相似解决方案