1. 程式人生 > >sprint boot計劃任務

sprint boot計劃任務

@Service
public class ScheduledTaskService {
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    @Scheduled(fixedRate = 5000)
    public void reportCurrentTime() {
        System.out.println("每隔5秒執行一次 " + dateFormat.format(new Date()));
    }

    @Scheduled
(cron = "0 23 9 ? * * ") public void fixTimeExecution() { System.out.println("在指定時間 " + dateFormat.format(new Date()) + "執行"); } } @Configuration @ComponentScan("ch3.taskscheduler") @EnableScheduling public class TaskSchedulerConfig { } public class Main { public static void main
(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TaskSchedulerConfig.class); } }