package com.zaimeibian.task;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class PrintTask {
DateFormat df = new SimpleDateFormat("HH:mm:ss");
@Async
@Scheduled(fixedRate = 2000)
public void printA(){
System.out.println("A执行 " + df.format(new Date()));
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
System.out.println("A打印输出 " + df.format(new Date())+ Thread.currentThread());
}
@Scheduled(fixedRate = 5000)
public void printB(){
System.out.println("B执行 " + df.format(new Date()));
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
System.out.println("B打印输出 " + df.format(new Date())+ Thread.currentThread());
}
@Scheduled(fixedRate = 5000)
public void printC(){
System.out.println("C执行 " + df.format(new Date()));
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
System.out.println("C打印输出 " + df.format(new Date())+ Thread.currentThread());
}
@Scheduled(fixedRate = 5000, initialDelay=1000)
public void printD(){
System.out.println("D执行 " + df.format(new Date()));
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
}
System.out.println("D打印输出 " + df.format(new Date())+ Thread.currentThread());
}
@Scheduled(fixedRate = 5000, initialDelay=1000)
public void printE(){
System.out.println("E执行 " + df.format(new Date()));
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
}
System.out.println("E打印输出 " + df.format(new Date())+ Thread.currentThread());
}
}