SSH项目使用scheduled定时任务

首先在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:工作中的记录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值