spring配置quartz 多任务

这是我的一个测试,我配的2个任务。
spring 的配置:

<!-- 与quartz有关的设置 -->
<bean id="billJob" class="test.BillReliabilityJob"/>
<bean id="exceptionJob" class="test.ExceptionJob"/>

<bean id="billJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="billJob"/><!-- 调用的Job类 -->
</property>
<property name="targetMethod">
<value>run</value><!-- 调用的类中的方法 -->
</property>
</bean>
<bean id="exceptionJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="exceptionJob"/><!-- 调用的Job类 -->
</property>
<property name="targetMethod">
<value>run</value><!-- 调用的类中的方法 -->
</property>
</bean>

<bean id="billRunTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="billJobTask"/>
</property>
<property name="cronExpression">
<value>0/5 * * * * ?</value>
</property>
</bean>
<bean id="ExceptionRunTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="exceptionJobTask"/>
</property>
<property name="cronExpression">
<value>10 * * * * ?</value>
</property>
</bean>

<!-- 总管理类,如果lazy-init='false',则容器启动时就会执行调度程序-->
<!-- 如果lazy-init='true',则需要实例化该bean才能执行调度程序 -->

<bean id="billStartQuartz" lazy-init="false" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="billRunTime"/>
<ref bean="ExceptionRunTime"/>
</list>
</property>
</bean>


运行时,首先我采用MainTest 测试

public class MainTest extends TestCase {

public void testJob(){
System.out.println("start");
ApplicationContext context = new FileSystemXmlApplicationContext(
"./config/spring.xml");
System.out.println("end");
}
}


发现程序打印end后就结束了。
然后我用Main测试,可以正常执行。

Java代码
public class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("start");
ApplicationContext context = new FileSystemXmlApplicationContext(
"./config/spring.xml");
System.out.println("end");
}

}

job类的内容为:

Java代码
public class ExceptionJob {

public void run(){
System.out.println("ExceptionJob running");
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值