@EnableScheduling
@Scheduled
package com.easywork.pp.controller;
import java.util.Date;
@EnableAsync
@EnableScheduling
@Controller
@RequestMapping("/home")
public class HomeController extends BaseController {
@Scheduled(fixedRate = 5000)
@Async
public void printTime(){
System.out.println(Thread.currentThread().getName()+"curTimeBegin"+new Date());
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+"curTimeEnd"+new Date());
}
}
单线程下无法完全遵循时间间隔
用异步方式:打上@Async