我想在java配置文件中的并行步骤执行中制作一个示例应用程序,但会困惑地指出需要配置多少文件(作业存储库,作业启动器和执行等)并初始化,如果配置,那么如何? 简而言之,我需要一个示例应用程序来阐明并行执行作业中步骤的基础知识。Spring批处理:在java配置文件中执行并行步骤
2
A
回答
3
下面是通过java配置使用分割的示例。在本例中,流程1和2将并行执行:
@Configuration
public class BatchConfiguration {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Bean
public Tasklet tasklet() {
return new CountingTasklet();
}
@Bean
public Flow flow1() {
return new FlowBuilder<Flow>("flow1")
.start(stepBuilderFactory.get("step1")
.tasklet(tasklet()).build())
.build();
}
@Bean
public Flow flow2() {
return new FlowBuilder<Flow>("flow2")
.start(stepBuilderFactory.get("step2")
.tasklet(tasklet()).build())
.next(stepBuilderFactory.get("step3")
.tasklet(tasklet()).build())
.build();
}
@Bean
public Job job() {
return jobBuilderFactory.get("job")
.start(flow1())
.split(new SimpleAsyncTaskExecutor()).add(flow2())
.end()
.build();
}
public static class CountingTasklet implements Tasklet {
@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
System.out.println(String.format("%s has been executed on thread %s", chunkContext.getStepContext().getStepName(), Thread.currentThread().getName()));
return RepeatStatus.FINISHED;
}
}
}
-1
这里是对不同数据集执行的基本并行步骤,基本上你必须提供一个分区器,它将为每个步骤创建单独的上下文,并根据上下文来处理它的数据集。
<batch:job id="myJob" job-repository="jobRepository">
<batch:step id="master">
<batch:partition step="step1" partitioner="stepPartitioner ">
<batch:handler grid-size="4" task-executor="taskExecutor"/>
</batch:partition>
</batch:step>
</batch:job>
<batch:step id="step1">
<batch:tasklet>
<batch:chunk reader="myReader" processor="myProcessor" writer="myWriter"
commit-interval="10"/>
</batch:tasklet>
</batch:step>
public class stepPartitioner implements Partitioner {
@Autowired
DaoInterface daoInterface;
@Override
public Map<String, ExecutionContext> partition(int i) {
Map<String, ExecutionContext> result = new HashMap<>();
List<String> keys= daoInterface.getUniqueKeyForStep();
for(String key: keys){
ExecutionContext executionContext = new ExecutionContext();
executionContext.putString("key", key);
result.put(key,executionContext);
}
return result;
}
}
+1
这不是一个javaconfig例如 –
+0
耶@sandeep那不是javaconfig例子。我需要的所有的javaconfig。 – maddy
2
假设您有步骤A,B1,B2,B3,C。您想要并行运行B1,B2 & B3。首先,您需要为他们创建子流,然后添加到一个流与SimpleAsyncTaskExecutor():
@Bean
public Job job()
{
final Flow flowB1 = new FlowBuilder<Flow>("subflowb1").from(stepb1()).end();
final Flow flowB2 = new FlowBuilder<Flow>("subflowb2").from(stepb2()).end();
final Flow flowB3 = new FlowBuilder<Flow>("subflowb3").from(stepb3()).end();
final Flow splitFlow = new FlowBuilder<Flow>("splitFlow")
.start(flowB1)
.split(new SimpleAsyncTaskExecutor())
.add(flowB2, flowB3).build();
return jobBuilderFactory
.flow(stepA())
.next(splitFlow)
.next(stepC())
.end()
.build();
}
相关问题
- 1. Spring批处理3.0.2使用批注的并行步骤
- 2. Spring批处理Java配置:跳过步骤,例外并转到下一步
- 3. 弹簧批量并行处理多次执行一个步骤
- 4. Spring批处理FlowJobBuilder:并行和顺序执行“jobStep”类型步骤
- 5. 在Spring批处理的Tasklet步骤中写入文件
- 6. 远程执行批处理文件java
- 7. 批处理文件执行
- 8. 在C#中执行批处理文件#
- 9. 在c#中执行批处理文件
- 10. 在批处理文件中执行httprequest
- 11. 如何在批处理文件中并行执行xcopy?
- 12. Spring批处理分区步骤未运行
- 13. Spring批处理并行处理
- 14. Spring批处理不会在并行模式下执行流。
- 15. Spring批处理Java配置JobLauncherTestUtils
- 16. 无法配置Spring批处理来运行java类吗?
- 17. db2 V10.5启用并行处理步骤
- 18. 延迟Java步骤执行
- 19. 在Java中执行批处理文件的问题
- 20. 在java中执行带有args的批处理文件
- 21. 在TeamCity 9的一个构建步骤中运行两个批处理文件
- 22. 在Spring批处理中创建迭代流程步骤
- 23. Java Spring批处理:如何验证执行是否并行完成?
- 24. 批处理文件执行ASP经典
- 25. 的MSBuild PSEXEC执行批处理文件
- 26. 从C#执行批处理文件#
- 27. Windows批处理文件执行日志
- 28. 非阻塞批处理文件执行
- 29. 窗体执行批处理文件
- 30. 批处理文件未完全执行
非常感谢@迈克尔。它的工作 – maddy
@maddy你介意接受这个答案吗? –
是的。因为我只想知道多个步骤如何并行运行。所以它给了我一个主意。 – maddy