Scheduling Tasks定时任务

来源:互联网 发布:g92车锥螺纹编程实例 编辑:程序博客网 时间:2024/05/16 15:27

1、项目包结构


2、文件说明:

@SpringBootApplication@EnableSchedulingpublic class Application {    public static void main(String[] args) throws Exception {        SpringApplication.run(Application.class);    }}


@Componentpublic class ScheduledTasks {    private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");    @Scheduled(fixedRate = 5000)    public void reportCurrentTime() {        log.info("The time is now {}", dateFormat.format(new Date()));    }}


3、响应