Spring实战 MethodInvokingJobDetailFactoryBean使用与分析

定义一个Job类

public class OffsetsQuartz {

    public void jobQuartz() {
        String[] clusterAliass = SystemConfigUtils.getPropertyArray("kafka.eagle.zk.cluster.alias", ",");
        for (String clusterAlias : clusterAliass) {
            execute(clusterAlias);
        }
    }
}
<bean id="offsetsSchedule" class="org.smartloli.kafka.eagle.web.quartz.OffsetsQuartz" />
	<!-- Method for configuring scheduling specific execution. -->
	<!-- task1 -->
	<bean id="offsetsDetail"
		class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<property name="targetObject" ref="offsetsSchedule" />
		<property name="targetMethod" value="jobQuartz" />
		<property name="concurrent" value="false" />
	</bean>
	<!-- Configure the trigger time for scheduling execution. -->
	<bean id="offsetsTrigger"
		class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
		<property name="jobDetail" ref="offsetsDetail" />
		<property name="cronExpression">
			<!--  per 5min 每5分钟重启一次-->
			<value>0 0/5 * * * ?</value>
		</property>
	</bean>
	<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序  -->
	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<!-- All scheduling lists. -->
				<ref local="offsetsTrigger" />
			</list>
		</property>
	</bean>
posted @ 2018-06-08 10:19  枫叶maple  阅读(2645)  评论(0编辑  收藏  举报