springBoot-计划任务

声明:代码是JavaEE开发的颠覆者 Spring Boot实战代码中的,我买了这书,并练习

@Configuration
@ComponentScan("com.wisely.highlight_spring4.ch3.taskscheduler")
@EnableScheduling //开启计划任务
public class TaskSchedulerConfig {

}

--------------------------
@Service
public class ScheduledTaskService {
	  @Scheduled(fixedRate = 5000) //1
	  public void reportCurrentTime() {
	  	System.out.println("每隔五秒执行一次:AAAA");
	   }
	  @Scheduled(cron = "30 * * * * *"  ) //2
	  public void fixTimeExecution(){
	      System.out.println("" +"每隔30秒执行一次:BBBB");
	  }
}

-------------------------
public class Main {
	public static void main(String[] args) {
		 AnnotationConfigApplicationContext context =
	                new AnnotationConfigApplicationContext(TaskSchedulerConfig.class);
	}
}

springBoot-计划任务_第1张图片

你可能感兴趣的:(SpringBoot)