【发布时间】:2015-11-27 18:52:08
【问题描述】:
我正在尝试在春季批处理中并行运行多个作业。在谷歌中进行大量搜索后,我遇到了 JobStep。有没有人使用过 JobStep 可以解释如何使用它来并行运行作业,或者是否有任何其他方式来运行2个独立的并行作业,即当我开始批处理时,2个作业应该开始并行运行 .我的要求是这样的
<batch:job id="JobA" incrementer="runIdIncrementer">
<batch:step id="abc">
<batch:tasklet transaction-manager="transactionManager">
<batch:chunk reader="ReaderA" writer="WriterA" processor="ProcessorA" />
</batch:tasklet>
</batch:step>
</batch:job>
<batch:job id="JobB" incrementer="runIdIncrementer">
<batch:step id="def">
<batch:tasklet transaction-manager="transactionManager">
<batch:chunk reader="ReaderB" writer="WriterB" processor="ProcessorB" />
</batch:tasklet>
</batch:step>
</batch:job>
当我的应用程序启动时,两个作业都应该开始运行。是否可以使用 spring batch 这样做
编辑:我什至尝试过这种方式
<batch:job id="ParallelJob" incrementer="runIdIncrementer" restartable="true">
<batch:split id="parallelprocessing" task-executor="taskExecutor">
<batch:flow>
<batch:step id="ParallelJob.step1" >
<batch:job ref="JobA" job-launcher="jobLauncher" job-parameters-extractor="jobParametersExtractor"/>
</batch:step>
</batch:flow>
<batch:flow>
<batch:step id="ParallelJob.step2" >
<batch:job ref="JobB" job-launcher="jobLauncher" job-parameters-extractor="jobParametersExtractor"/>
</batch:step>
</batch:flow>
</batch:split>
</batch:job>
<batch:job id="JobA" restartable="true">
<batch:step id="abc">
<batch:tasklet >
<batch:chunk reader="reader" writer="writer" processor="processor" />
</batch:tasklet>
</batch:step>
</batch:job>
<batch:job id="JobB" restartable="true">
<batch:step id="abc">
<batch:tasklet >
<batch:chunk reader="reader" writer="writer" processor="processor" />
</batch:tasklet>
</batch:step>
</batch:job>
我面临异常说 org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有定义 [org.springframework.batch.core.Job] 类型的合格 bean:预期的单个匹配 bean 但找到了 3:ParallelJob、JobA、JobB。我正在使用 commandLineJobRunner 和将 jobId 传递为ParallelJob
【问题讨论】:
-
您希望能够同时执行这两个作业作为作业的一部分吗?还是只是在您的申请开始后立即开始这两项工作?或者你想以任意方式同时执行这两个作业?
标签: java spring parallel-processing spring-batch