spring-projects / spring-batch

Spring Batch is a framework for writing batch applications using Java and Spring
http://projects.spring.io/spring-batch/
Apache License 2.0
2.71k stars 2.34k forks source link

First flow never executed when running parrallel flows [BATCH-2346] #1256

Closed spring-projects-issues closed 9 years ago

spring-projects-issues commented 9 years ago

Walter Morykon opened BATCH-2346 and commented

When attempting to execute multiple flow in parallel e.g.

FlowBilder flowBuilder = FlowBuilder<SimpleFlow>("Parallel Flows")
                .start(flowA)
                .split(new SimpleAsyncTaskExecutor())
                .add(flowB, flowC)
                .build()

The result is that flowB and flowC run in parallel, but flowA never runs.

Looking at the add method of the FlowBuilder class

public FlowBuilder<Q> add(Flow... flows) {
    Collection<Flow> list = new ArrayList<Flow>(Arrays.asList(flows));
    String name = "split" + (parent.splitCounter++);
    int counter = 0;
    State one = parent.currentState;
    Flow flow = null;

    if (!(one instanceof FlowState)) {
        FlowBuilder<Flow> stateBuilder = new FlowBuilder<Flow>(name + "_" + (counter++));
        stateBuilder.currentState = one;
        flow = stateBuilder.build();
    }

    if (flow != null) {
        list.add(flow);
    }

    State next = parent.createState(list, executor);
    parent.currentState = next;
    return parent;
}

Since flowA is wrapped in a FlowState it will not be added to the list and hence will not be run by the executor.


Affects: 3.0.3

2 votes, 4 watchers

spring-projects-issues commented 9 years ago

Michael Minella commented

Fixed: https://github.com/spring-projects/spring-batch/commit/652ca038f901e0425935d298ce565a0efa0bcaaa