Skip to content

Commit 7812c00

Browse files
acktsapfmbenhassine
authored andcommitted
Prevent race condition when flow transition is not initialized
Resolves #4092 (cherry picked from commit 99e8d58)
1 parent d9d6a8d commit 7812c00

File tree

1 file changed

+10
-6
lines changed
  • spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support

1 file changed

+10
-6
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/SimpleFlow.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
* @author Dave Syer
4949
* @author Michael Minella
5050
* @author Mahmoud Ben Hassine
51+
* @author Taeik Lim
5152
* @since 2.0
5253
*/
5354
public class SimpleFlow implements Flow, InitializingBean {
@@ -124,19 +125,16 @@ public Collection<State> getStates() {
124125
*/
125126
@Override
126127
public void afterPropertiesSet() throws Exception {
127-
if (startState == null) {
128-
initializeTransitions();
129-
}
128+
initializeTransitionsIfNotInitialized();
130129
}
131130

132131
/**
133132
* @see Flow#start(FlowExecutor)
134133
*/
135134
@Override
136135
public FlowExecution start(FlowExecutor executor) throws FlowExecutionException {
137-
if (startState == null) {
138-
initializeTransitions();
139-
}
136+
initializeTransitionsIfNotInitialized();
137+
140138
State state = startState;
141139
String stateName = state.getName();
142140
return resume(stateName, executor);
@@ -262,6 +260,12 @@ protected boolean isFlowContinued(State state, FlowExecutionStatus status, StepE
262260
return continued;
263261
}
264262

263+
private synchronized void initializeTransitionsIfNotInitialized() {
264+
if (startState == null) {
265+
initializeTransitions();
266+
}
267+
}
268+
265269
/**
266270
* Analyse the transitions provided and generate all the information needed to execute
267271
* the flow.

0 commit comments

Comments
 (0)