SpringBootオリジナルタイミングタスク解析

866 ワード

SpringBootオリジナルタイミングタスク、依存を導入する必要はありません
==わかりさえすれば、いくつかの注釈が使えます==
  • 1.起動クラスに@EnableSchedulingラベル
  • を追加
  • 2.タイミングタスクメソッドに@Schedule(fixedDelay=5000)
  • を加える
  • 3.このように簡単で、簡単なのは想像できません
  • package zebra.shjf;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.ConfigurableApplicationContext;
    import org.springframework.scheduling.annotation.EnableScheduling;
    
    @SpringBootApplication
    @EnableScheduling
    public class TestQuartzApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(TestQuartzApplication.class, args);
        }
    }
    
    
    @Component
    public class ScheduledTasks{
        @Scheduled(fixedDelay = 5000)
        public void execute() {
            System.out.println("    :" + new Date());
        }
    }