master
bseayin 2019-08-17 21:19:59 +08:00
parent cd40074db5
commit bb8693eeaa
2 changed files with 72 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package com.zz;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
/** /**
* --run as application mainspringboot * --run as application mainspringboot
SpringBoot tomcat main tomcat SpringBoot tomcat main tomcat
@ -9,6 +10,7 @@ SpringBoot 自带了 tomcat 运行这个main方法 的时候,会同时启
* *
*/ */
@SpringBootApplication @SpringBootApplication
@EnableScheduling
public class App { public class App {
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -0,0 +1,70 @@
package com.zz.util;
import java.time.LocalDateTime;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class TimerDemo1 {
/**
* fixedRate
使
使
@Scheduled(fixedRate = 3000)
public void scheduledTask() {
System.out.println("Task executed at " + LocalDateTime.now());
}
*/
/**https://www.jianshu.com/p/73784dff0b0e
* Cron
96
2018.08.01 22:23* 580 201 0 1
Cron Spring @Scheduled
Cron 6 7 使
6 Cron
Seconds Minutes Hours DayofMonth Month DayofWeek
7 Cron
Seconds Minutes Hours DayofMonth Month DayofWeek Year
使
Seconds0~59 , - * /
Minutes Seconds
Hours0~23 , - * /
DayofMonth0~31 , - * / ? L W C
Month1~12 JAN ~ DEC , - * /
DayofWeek1~7 SUN ~ SAT , - * / ? L C # 1
Year1970~2099 , - * /
*/
/**
* (1) ,
Seconds 使 10,15,25 10 15 25
*/
@Scheduled(cron = "10,15,25 * * * * ?")
public void scheduledTask() {
System.out.println("Task executed at " + LocalDateTime.now());
}
//每个月的30号凌晨执行
@Scheduled(cron = "0 0 0 30 * ? ")
public void scheduledTask2() {
System.out.println("Task executed at " + LocalDateTime.now());
}
}