Spring Batch任务的异步执行

Spring Batch的默认执行的流程如下:

Spring Batch任务的异步执行_第1张图片

如果想同时执行多个Job,那么就要用到Spring Batch的异步执行方式,这种方式如下:

Spring Batch任务的异步执行_第2张图片

这在通过web页面执行任务的时候,也会非常有用,不会让页面阻塞。

我们只需要在原来的程序上,加上如下配置即可:

<bean:bean id="jobLauncher"
		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
		<bean:property name="jobRepository" ref="jobRepository" />
		<bean:property name="taskExecutor">
			<bean:bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"></bean:bean>
		</bean:property>
	</bean:bean>

注意:我们使用了SimpleAsyncTaskExecutor这个类做为任务的执行类。

你可能感兴趣的:(spring,异步,batch)