1、
@Service
public class ScheduledService {
//second, minute, hour, day of month, month, and day of week.
@Scheduled(cron = "0 * * * * MON-SAT")
public void test(){
System.out.println("test...");
}
}
2、
@EnableScheduling //开启基于注解的定时任务
@SpringBootApplication
public class TaskApplication {
public static void main(String[] args) {
SpringApplication.run(TaskApplication.class, args);
}
}
3、
@Scheduled(cron = "0,1,2,3,4 * * * * MON-SAT")
@Scheduled(cron = "0-4 * * * * MON-SAT")
@Scheduled(cron = "0/4 * * * * MON-SAT")