天天看點

Spring 定時器配置執行個體

配置Spring定時器的觸發器的代碼如下:

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
	<property name="triggers">
		<list>
			<ref local="cronTrigger_excute_must_value_enter" />
		</list>
	</property>
	<!-- QuartzScheduler 延時啟動,應用啟動完後 QuartzScheduler 再啟動 -->
	<property name="startupDelay" value="20" />
	<!-- 設定線程數,日志 -->
	<property name="quartzProperties">
		<props>
			<prop key="org.quartz.threadPool.threadCount">1</prop>
			<prop key="org.quartz.plugin.triggHistory.class">org.quartz.plugins.history.LoggingJobHistoryPlugin
			</prop>
		</props>
	</property>
</bean>

<bean id="cronTrigger_excute_must_value_enter" class="org.springframework.scheduling.quartz.CronTriggerBean">
	<property name="jobDetail">
		<ref bean="jobDetail_excute_must_attr_enter" />
	</property>
	<property name="cronExpression">
		<value>0 05 01 * * ? </value>
	</property>
</bean>

<bean id="jobDetail_excute_must_value_enter"
	class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
	<property name="targetObject">
		<ref bean="holdProductOperateRpcService" />
	</property>
	<property name="targetMethod">
		<value>checkIsEnterMustAttr_noTrans</value>
	</property>
</bean>	      

需要修改的地方是:

<property name="targetObject">
		<ref bean="holdProductOperateRpcService" />
	</property>
	<property name="targetMethod">
		<value>checkIsEnterMustAttr_noTrans</value>
	</property>      

targetObject 的值是要執行的service,targetMethod的值是:要執行service中的方法。