我想在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