spring task定时器

版本要求:spring 3.0以上

添加引入:

xmlns:task="http://www.springframework.org/schema/task"

http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd

具体配置如下:

<!-- 任务id,定时调度的具体类文件 -->   
    <bean id="orderPayRemindTask" class="com.xt.elefox.task.OrderPayRemindTask"></bean>
   
    <!-- 定时器开关 -->
    <task:annotation-driven />
   
    <!-- 定时配置 -->   
    <task:scheduled-tasks scheduler="orderPayRemindScheduler"> 
        <task:scheduled ref="orderPayRemindTask" method="compareUnpaidTime" cron="0/5 * * * * ?"/> 
    </task:scheduled-tasks> 
    <!-- 线程池 (如果多个任务同时执行,切没有线程池配置的话,同线程下会出现队列等待的情况,或者使用不同的scheduled配置不同的任务)--> 
    <task:scheduler id="orderPayRemindScheduler" pool-size="10"/>

java文件:

public class OrderPayRemindTask {
    private static final Log log = LogFactory.getLog(OrderPayRemindTask.class);
   
    //比较未支付时间,如果超时未支付给予消息提醒
    public void compareUnpaidTime(){
        log.info("compareUnpaidTime start...");
       
        log.info("compareUnpaidTime end...");
    }
}

猜你喜欢

转载自sky10198866.iteye.com/blog/2330723