springboot已经支持了定时任务Schedule模块,所以一般情况已经完全能够满足我们的实际需求.
package com.bdbk.spider.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
@Component
public class ScheduleConfig {
/**
* 定时取消订单
*/
@Scheduled(cron = "0 0 0/4 * * ?") //定时器定义,设置执行时间,每隔4个小时
private void () {
cancelOrder();
}
}
点击查看 定时任务设置