我们知道生活中有很多定时器,比如闹钟,水壶,燃油表......当然程序中的定时器是最为显眼的。
package task;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@EnableScheduling
public class MayTask {
private int count =1;
@Scheduled(cron = "* * * * * *")
public void task() {
System.out.println("第"+count+++"次执行任务,当前时间:"+
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
}
}