spring实现定时任务
2016-11-26 00:00
357 查看
1.创建一个定时任务控制器
/** * 描述:定时器 * 作者:温海金 * 最后更改时间:下午5:29:49 */ public class TaskTimerScanner { @Resource private TaskTimerScannerI taskTimerScanner; /** * 功能描述:若30分钟没有付款则更改订单表的状态为订单失效 同时将包车状态改为已取消 */ public int updateOrderStatus2Invalid() { return taskTimerScanner.updateOrderStatus2Invalid();//调用业务层实现具体的定时业务 } }
2.添加一个定时任务配置:spring-tasks.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <!-- Spring定时器注解开关--> <task:annotation-driven /> <!-- cron表达式:* * * * * *(共6位,使用空格隔开,具体如下) cron表达式:*(秒0-59) *(分钟0-59) *(小时0-23)*(日期1-31) *(月份1-12或是JAN-DEC) *(星期1-7或是SUN-SAT) 例如@Scheduled(cron="0/5 * * * * ? ")表示初始化的时候执行一次然后每5秒执行一次--> <!-- <task:scheduled ref="scheduledTaskManager" method="invalidOrderStatus" cron="10/5 * * * * *"/> --> <task:scheduled-tasks scheduler="myScheduler"> <!-- 若30分钟没有付款则更改订单表的状态为订单失效 --> <task:scheduled ref="myTaskTimerScanner" method="updateOrderStatus2Invalid" cron="0/5 * * * * ? "/> </task:scheduled-tasks> <task:scheduler id="myScheduler" pool-size="10"/> </beans>
3.在spring的主配置文件中配置一个bean管理定时任务控制类,同时引入spring-tasks.xml
<bean id="myTaskTimerScanner" class="com.lantaiyuan.ebus.custom.scheme.TaskTimerScanner"/> <!-- 引入spring的定时器 --> <import resource="classpath:spring/spring-tasks.xml" />
相关文章推荐
- Spring与Quartz的整合实现定时任务调度
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- spring实现定时任务的两种方式之Spring 3整合Quartz 2实现定时任务
- Spring结合Quartz实现多任务定时调用
- spring容器框架定时任务实现的两种方式
- java中 spring 定时任务 实现代码
- Spring 整合 Quartz 实现动态定时任务(附demo)
- spring注解 实现定时任务
- spring定时任务(利用Quartz实现)
- Spring定时任务的几种实现
- 利用spring+quartz-scheduler+MySql实现定时任务动态调整
- Spring实现定时任务方法
- Spring定时任务的几种实现
- Spring 3整合Quartz 2实现定时任务一:常规整合
- 【转】Spring 整合 Quartz 实现动态定时任务
- Spring整合Quartz实现定时任务调度
- Spring+Quartz实现定时任务的配置方法
- cool-2018-03-07-spring整合quartz实现定时任务
- springboot整合Quartz实现动态配置定时任务