import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* Spring框架提供的定时器
* @author admin
*
*/
@Component
@Configurable
@EnableScheduling
public class SpringScheduleJobDemo {
private static final Logger logger = LoggerFactory.getLogger(SpringScheduleJobDemo.class);
@Autowired
private JobService jobService;
@Autowired
private NeedRepository needRepository;
/**
* 任务轮询:每15分钟执行一次计划任务
* @throws Exception
*/
@Scheduled(cron = "0 5/15 * * * ?")
public void doQuery() throws Exception{
logger.info("开始任务");
logger.info("结束任务");
}
}
Spring框架 计划任务Schedule job demo
最新推荐文章于 2024-05-21 11:44:07 发布