我正在尝试在春天并行运行多个作业在谷歌的大量搜索中我遇到了JobStep.Has任何使用JobStep的人都可以解释如何使用它来并行运行作业,或者是否有任何其他方法来并行运行2个独立的作业,即当我开始批处理2个作业时,应该开始并行运行.My要求是这样的
<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>当我的应用程序启动时,两个作业都应该启动running.Is,这可以使用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,job。我正在使用commandLineJobRunner启动作业并传递jobId asParallelJob
发布于 2015-11-28 05:17:39
定义:
<batch:job id="globalJob">
<batch:split id="StepOne">
<batch:flow>
<batch:step id="step1" >
<batch:job ref="jobRef1"/>
</batch:step>
</batch:flow>
<batch:flow>
<batch:step id="step2">
<batch:job ref="jobRef2"/>
</batch:step>
</batch:flow>
</batch:split>
</batch:job>在需要的时候执行作业:
@Autowired
JobLauncher jobLauncher;
@Autowired
@Qualifier("globalJob")
Job globalJob;
@Override
public void executeGlobalJob() throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException {
try {
jobLauncher.run(globalJob,new JobParameters());
} catch (JobExecutionAlreadyRunningException e) {
throw new JobInstanceAlreadyExistsException("JobExecutionAlreadyRunningException",e);
} catch (JobRestartException e) {
throw new JobInstanceAlreadyExistsException("JobRestartException",e);
} catch (JobInstanceAlreadyCompleteException e) {
throw new JobInstanceAlreadyExistsException("JobInstanceAlreadyCompleteException",e);
}
}}
在应用程序启动后执行作业,只需设置属性:
spring.batch.job.names=globalJobhttps://stackoverflow.com/questions/33963337
复制相似问题