Spring框架 计划任务Schedule job demo

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("结束任务");
    }
    
}

猜你喜欢

转载自franciswmf.iteye.com/blog/2357964