@Component
@Lazy(false)
public class TestScheduled {
// 秒、分、时、天、月份、星期、年
@Scheduled(cron = "0/5 * * * * ?")
public void testSheduled() throws InterruptedException {
System.out.println("clean:"+new Date().getTime() + ":" +Thread.currentThread().getName());
Thread.sleep(10000);
System.out.println("clean:"+new Date().getTime() + ":" +Thread.currentThread().getName()+":task end");
}
}
@SpringBootApplication
@EnableScheduling
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class);
}
}
cron允许值: 秒 分 小时 日期 月份 星期 年份
常用选项: