方法一:
一个定时配置文件可以设置一个定时任务,所以两个定时配置文件可以设置两个定时任务。
方法二:
在同一个配置文件中增加定时任务
<?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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
default-autowire="byName" default-lazy-init="true">
<!-- 定时同步渠道任务-这是定时任务要跑的类 -->
<bean id="synchroAgentJob" class="TriggerAction"></bean>
<bean id="synchroAgentJob2" class="TriggerAction2"></bean>
<bean id="synchroAgentJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="synchroAgentJob" /> <!-- 配置调度的定时任务 -->
<property name="targetMethod" value="方法名" /> <!-- 配置调度定时任务中的方法 -->
<property name="concurrent" value="false" /> <!-- 是否并发执行 -->
</bean>
<bean id="synchroAgentJobDetail2" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="synchroAgentJob2" /> <!-- 配置调度的定时任务 -->
<property name="targetMethod" value="方法名" /> <!-- 配置调度定时任务中的方法 -->
<property name="concurrent" value="false" /> <!-- 是否并发执行 -->
</bean>
<!-- 触发器 配置定时任务的调度的时间 -->
<bean id="synchroAgentTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="synchroAgentJobDetail" />
<property name="cronExpression">
<value>0 0/1 * * * ?</value><!-- [秒] [分] [时] [日] [月] [年] -->
</property>
</bean>
<bean id="synchroAgentTrigger2" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="synchroAgentJobDetail2" />
<property name="cronExpression">
<value>0 0/1 * * * ?</value><!-- [秒] [分] [时] [日] [月] [年] -->
</property>
</bean>
<!--定义调度器 --><!-- lazy-init='false'容器启动就会执行调度程序 -->
<bean id="myscheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false" autowire="no">
<property name="triggers">
<list>
<ref bean="synchroAgentTrigger2" />
<ref bean="synchroAgentTrigger" />
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.threadPool.threadCount">1</prop><!-- 设置线程并发数 -->
</props>
</property>
</bean>
</beans>