java定时任务

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:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
						http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"
	default-lazy-init="true">

	<description>racAccountQuartz的定时任务配置</description>

	<bean id="racAccountTask" class="com.cacss.itas.rac.schedule.RacAccountQuartzTask"></bean>
      
    <bean id="RacschedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref bean="banKAccountTrigger" />
				<ref bean="chartOfAccountTrigger"/>
			</list>
		</property>
	</bean> 
	
	<!-- bankAccountTask  -->
	<bean id="banKAccountTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
		<property name="jobDetail">
			<ref bean="bankAccountJobDetail" />
		</property>
		<property name="cronExpression">
			<value>0 5 0 * * ?</value>
		</property>
	</bean>
	
    <!--schedule manage  -->
	<bean id="bankAccountJobDetail"
		class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    	<property name="concurrent" value="false"/>
		<property name="targetObject" ref="racAccountTask"></property>
		<property name="targetMethod" value="bankAccountTask"></property>
	</bean>
	
	<!-- chartOfAccountTrigger -->
	<bean id="chartOfAccountTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
		<property name="jobDetail">
			<ref bean="chartOfAccountJobDetail" />
		</property>
		<property name="cronExpression">
			<value>0 5 0 * * ?</value>
		</property>
	</bean>
	
    <!--schedule manage  -->
	<bean id="chartOfAccountJobDetail"
		class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    	<property name="concurrent" value="false"/>
		<property name="targetObject" ref="racAccountTask"></property>
		<property name="targetMethod" value="chartOfAccountTask"></property>
	</bean>
</beans>

RacAccountQuartzTask.java

package com.cacss.itas.rac.schedule;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cacss.itas.rac.service.ext.IRacBankAccountProcessService;
import com.cacss.itas.rac.service.ext.IRacChartOfAccountProcessService;

@Component
public class RacAccountQuartzTask {
	private static final Logger logger = Logger.getLogger(RacAccountQuartzTask.class);
	
	@Autowired
	IRacBankAccountProcessService iRacBankAccountProcessService;
	
	@Autowired
	IRacChartOfAccountProcessService iRacChartOfAccountProcessService;
	
	/**
	 * update bank account status
	 */
	public void bankAccountTask() {
		try {
			iRacBankAccountProcessService.updateAccountStatus();
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
	}
	
	/**
	 * update chart of account status
	 */
	public void chartOfAccountTask() {
		try {
			iRacChartOfAccountProcessService.updateAccountStatus();
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值