Others_3_Task

hayeka發表於2020-03-08
package cn.boxku;

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

@SpringBootApplication
@EnableAsync
@EnableScheduling//開啟定時功能註解
public class AsynchronousApplication {

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

}
package cn.boxku.service;

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

import java.util.Date;

/**
 * ————————————————————————————————————————————————
 * CREATED BY hayeka ON 2020/3/8 17:19
 * ————————————————————————————————————————————————
 */
@Service
public class ScheduledService {


    //cron表示式
    //秒 分 時 日 月 周幾~
    @Scheduled(cron = "0/5 0/1 17 * * ?")
    public void hello()
    {
        System.out.println(new Date());
        System.out.println("你被執行了");
    }


}
本作品採用《CC 協議》,轉載必須註明作者和本文連結

一個從事軟體開發職業的經濟愛好者