定时任务配置详解

<!-- 触发回单正常推送任务 -->
<bean id="bspReceiptNormalPushTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="bspReceiptNormalPushJob" />
<property name="cronExpression" value="0 0/1 * * * ?" /><!-- 每隔1分钟触发一次 -->
</bean>
<bean id="bspReceiptNormalPushJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">  
        <property name="jobClass" value="com.MyDetailQuartzJobBean" />  
        <property name="jobDataAsMap">  
                <map>  
  <!-- 要反射的service -->
                      <entry key="targetObject" value="bspReceiptCallService" />  
<!-- 要反射的service 中要执行的方法 -->
                      <entry key="targetMethod" value="batchBspReceiptNormalPush" />  
                      <!-- 是否允许任务并发执行。当值为false时,表示必须等到前一个线程处理完毕后才再启一个新的线程 -->
                      <entry key="concurrent" value="false" />  
                </map>  
        </property>  

    </bean>


MyDetailQuartzJobBean.java


import java.lang.reflect.Method;


import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.QuartzJobBean;


import com.sfiec.oms.common.SpringUtil;


public class MyDetailQuartzJobBean extends QuartzJobBean {
private static final Logger LOGGER = LoggerFactory.getLogger(MyDetailQuartzJobBean.class);

private String targetObject;
private String targetMethod;


@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
try {
LOGGER.debug("execute [" + targetObject + "] at once >>>>>>");
Object otargetObject = SpringUtil.getBean(targetObject);
Method m = null;
try {
m = otargetObject.getClass().getMethod(targetMethod);
m.invoke(otargetObject);
} catch (SecurityException e) {
LOGGER.error(e.getMessage());
} catch (NoSuchMethodException e) {
LOGGER.error(e.getMessage());
}
} catch (Exception e) {
throw new JobExecutionException(e);
}
}


public void setTargetObject(String targetObject) {
this.targetObject = targetObject;
}


public void setTargetMethod(String targetMethod) {
this.targetMethod = targetMethod;
}
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值