1、在类注解上加上EnableScheduling 声明定时器
2、在类注解上加上EnableAsync声明这是并行
3、在每个需要并行的任务上加上@Async
4、需要在Application中 加上@EnableScheduling注解,来开启定时器
5、其中fixedDelayString 可以在xml文件中定义时间;多久执行一次
6、还可以设置Cron 设置每个固定时间执行
Cron生成网址:http://cron.qqe2.com/
@Component
@Configurable
@EnableScheduling
@EnableAsync
public class ScheduleConfig{
@Async
@Scheduled(fixedDelayString = "${task.exec.time.Customer.delayed}")
public void UpdateCustomerCloud() throws Exception {
//把本地数据同步到服务器中
customerController.LocalUploadCustomerServer();
}
@Async
@Scheduled(fixedDelayString = "${task.exec.time.Employee.delayed}")
public void UpdateEmployeeCloud() throws Exception {
//把本地数据同步到服务器中
employeeController.LocalUploadEmployeeServer();
}