Skip to content

SplitBuilder.add(Flow) causes hung execution in some cases #3857

Closed
@ee-usgs

Description

@ee-usgs

Bug description
If FlowBuild.SplitBuilder.add(Flow) is called multiple times to dynamically build a list of Flows, the result is a Flow that will hang.
Calling FlowBuild.SplitBuilder.add(Flow[]) with an array of Flows works as expected.

For instance, this does not error, but does not work as expected:

FlowBuilder<SimpleFlow> myFlow = new FlowBuilder<SimpleFlow>("DoesntWork");
FlowBuilder.SplitBuilder<SimpleFlow> split = myFlow.split(exe);

for (int i = 0; i < 10; i++) {
	split.add(createANewFlow(i)); // <<< Key change - call add() multiple times
}

However, this does work:

FlowBuilder<SimpleFlow> myFlow = new FlowBuilder<SimpleFlow>("Works");

List<Flow> flows = new ArrayList<>();
for (int i = 0; i < 10; i++) {
	flows.add(createANewFlow(i));
}

myFlow.split(exe).add(flows.toArray(new Flow[flows.size()]));   //Add flows all in one 'add' operation

Why would you call FlowBuild.SplitBuilder.add(Flow) multiple times??
I need to dynamically build my list of tasks - I don't know the size of the list or what the tasks are ahead of time. I do know, however, that they can all be run in parallel and there are a lot of them (hundreds). Calling FlowBuild.SplitBuilder.add(Flow) for each as I build up the list makes the most intuitive sense.

Environment
Note: I'm pretty sure this is related to how SpringBatch works, not any sort of JDK issue.
SpringBatchCore 4.3.1
OpenJDK 12
Mac OS 10.14

Steps to reproduce
See the code example in GitHub, below.

The first flows runs as expected, the second flow hangs after two steps are executed.

Expected behavior
Calling FlowBuild.SplitBuilder.add(Flow) should just add to the list of flows to run in parallel. It shouldn't matter if they are added all at once or add is called multiple times.

Minimal Complete Reproducible example
I created a Maven based demo project that shows this bug:
https://github.com/ee-usgs/springbatch_parallel_bug

This application should be runnable via Maven or any IDE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions