import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}



import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class ScheduledTasks {

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    @Scheduled(fixedRate = 5000)
    public void reportCurrentTime() {
        System.out.println("当前时间:" + dateFormat.format(new Date()));
    }

}


每隔5秒执行:

SpringBoot--Timer

相关文章:

  • 2022-02-18
  • 2021-05-23
  • 2021-11-29
  • 2021-11-03
  • 2021-12-08
  • 2021-04-14
  • 2021-12-24
  • 2021-07-10
猜你喜欢
  • 2022-12-23
  • 2021-06-19
  • 2022-02-04
  • 2022-12-23
相关资源
相似解决方案