Scheduling Tasks定时任务

1、项目包结构

Scheduling Tasks定时任务_第1张图片

2、文件说明:

@SpringBootApplication
@EnableScheduling
public class Application {

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


@Component
public 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、响应

Scheduling Tasks定时任务_第2张图片



你可能感兴趣的:(Scheduling Tasks定时任务)