首先在spring.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:task="http://www.springframework.org/schema/task"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!-- 自己使用的action路径 -->
<bean id="yinsjhAction" class="com.action.YinsjhAction" scope="prototype">
<property name="yinsjhService" ref="yinsjhService" />
</bean>
<bean id="yinsjhService" class="com.service.YinsjhServiceImpl">
<property name="dao" ref="baseDao" />
</bean>
<!-- 加载定时任务的类 -->
<bean id="ysjhJobs" class="com.zjcw.ysjh.service.YsjhJobs">
</bean>
<!-- ref:加载的id,method: 类中使用的方法,cron: 定义的执行任务时间-->
<task:scheduler id="scheduler" pool-size="5" />
<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="ysjhJobs" method="runDemo" cron="*/10 * * * * ?" />
</task:scheduled-tasks>
</beans>
public static void runDemo(){
logger.info("-------------定时推送任务开始-----------------");
try {
logger.info("业务处理");
System.out.println("123-123");
} catch (Exception e) {
// TODO Auto-generated catch block
logger.error("任务执行失败",e);
}
logger.info("--------------业务处理结束---------------");
}
ps:工作中的记录