如何在SSH项目中布置多个定时任务?

方法一:

一个定时配置文件可以设置一个定时任务,所以两个定时配置文件可以设置两个定时任务。


方法二:

在同一个配置文件中增加定时任务


<?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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值