Sping 执行Quart的Job

这里给出一个Spring执行Quartz的Job的情况:

这个支持 Quartz1.x 和 Quartz2.x 的Quartz的版本。

public interface Job extends State{
	public void execute();
}

public class InitializeDataSourceMapJob implements Job {
	private static final Logger LOGGER = LoggerFactory
			.getLogger(InitializeDataSourceMapJob.class);
	@Override
	public void execute() {
		if(LOGGER.isInfoEnabled()){
			LOGGER.info(this.getClass().getName() +" start to work.");
		}
	}

}

 spring的配置文件:

	<!-- job start -->
	<!-- 这里我指定 init-method="execute" 主要是希望这个job能在类在加载的过程中就被运行。你可以去掉。-->
	<bean id="initializeDataSourceMapJob" class="test.job.impl.InitializeDataSourceMapJob"
		init-method="execute"/>
	
	<bean id="initializeDataSourceMapJobDetail"
		class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<property name="targetObject" ref="initializeDataSourceMapJob" />
		<property name="targetMethod" value="execute" />
		<property name="concurrent" value="false" />
	</bean>
	<bean id="initializeDataSourceMapJobCronTrigger"
		class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
		<property name="jobDetail" ref="initializeDataSourceMapJobDetail" />
		<property name="cronExpression" value="0 0/2 * * * ? *" />
	</bean>
	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref bean="initializeDataSourceMapJobCronTrigger" />
			</list>
		</property>
	</bean>
	<!-- job end -->

 

你可能感兴趣的:(ping)