我正在使用SpringBatch 3.0.2並試圖創建一個使用帶註釋的JavaConfig樣式和JobBuilderFactory類執行一系列步驟(其中一些並行)的作業。我想要發生的是從step1開始,並在它完成時轉換到所有並行運行的step2a,step2b,step2c和step2d。當所有這些步驟完成後,它應該轉換到步驟3。我正在努力創造這項工作所需的語法Spring批處理3.0.2使用批註的並行步驟
@Bean(name = "SplitFlowJob4")
public Job splitFlowJob4() throws SQLException
{
final Flow flow2b = new FlowBuilder<Flow>("subflow2b").from(step2b()).end();
final Flow flow2c = new FlowBuilder<Flow>("subflow2c").from(step2c()).end();
final Flow flow2d = new FlowBuilder<Flow>("subflow2d").from(step2d()).end();
return jobs.get("SplitFlowJob4").start(step1()).next(step2a()).split(new SimpleAsyncTaskExecutor())
.add(flow2b, flow2c, flow2d).next(step3()).end().build();
}
這不起作用,因爲我原本打算。這僅執行步驟1和步驟2a。我沒有看到step2b,2c,2d或step3。
[INFO ] [main] 2015-02-09 15:28:32,169 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep1]
[INFO ] [main] 2015-02-09 15:28:32,194 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep2a]
如果我改變的語法和從步驟1調用分裂,然後步驟1,2A,2B,2C,2D的所有並行執行,而不是僅僅步驟2A,2B,2C,2D。
@Bean(name = "SplitFlowJob5")
public Job splitFlowJob5() throws SQLException
{
final Flow flow2a = new FlowBuilder<Flow>("subflow2a").from(step2a()).end();
final Flow flow2b = new FlowBuilder<Flow>("subflow2b").from(step2b()).end();
final Flow flow2c = new FlowBuilder<Flow>("subflow2c").from(step2c()).end();
final Flow flow2d = new FlowBuilder<Flow>("subflow2d").from(step2d()).end();
return jobs.get("SplitFlowJob5").start(step1()).split(new SimpleAsyncTaskExecutor())
.add(flow2a, flow2b, flow2c, flow2d).next(step3()).end().build();
}
這並行執行步驟1,步驟2a,步驟2b,步驟2c,步驟2d。
[INFO ] [SimpleAsyncTaskExecutor-2] 2015-02-09 16:28:36,507 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep2b]
[INFO ] [SimpleAsyncTaskExecutor-5] 2015-02-09 16:28:36,513 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep1]
[INFO ] [SimpleAsyncTaskExecutor-3] 2015-02-09 16:28:36,512 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep2c]
[INFO ] [SimpleAsyncTaskExecutor-4] 2015-02-09 16:28:36,509 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep2d]
[INFO ] [SimpleAsyncTaskExecutor-1] 2015-02-09 16:28:36,507 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep2a]
[INFO ] [main] 2015-02-09 16:28:36,615 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep3]
我不知道我在做什麼錯,是否有可能使用流利的構建器API來創建這樣的工作?我已經看到了其他以分裂開始或結束的實例,但我還沒有看到一個在工作中包含分裂的例子。
這解決了這個問題對我來說。我將我的gradle依賴關係更新爲3.1.0.BUILD-SNAPSHOT版本。我確實不得不改變語法,因爲第一次調用next()需要一個Step而不是Flow。我沒有將步驟傳遞給start(),而是爲Step1創建了一個Flow並將其傳遞給start()。我不知道是否有更好的方法來做到這一點,但它對我有用。 – Randy 2015-02-10 13:58:56