Prevent race condition when flow transition is not initialized

Resolves #4092
This commit is contained in:
Taeik Lim
2022-04-11 23:29:06 +09:00
committed by Mahmoud Ben Hassine
parent 5e515473de
commit 99e8d58c13

View File

@@ -48,6 +48,7 @@ import org.springframework.beans.factory.InitializingBean;
* @author Dave Syer
* @author Michael Minella
* @author Mahmoud Ben Hassine
* @author Taeik Lim
* @since 2.0
*/
public class SimpleFlow implements Flow, InitializingBean {
@@ -124,9 +125,7 @@ public class SimpleFlow implements Flow, InitializingBean {
*/
@Override
public void afterPropertiesSet() throws Exception {
if (startState == null) {
initializeTransitions();
}
initializeTransitionsIfNotInitialized();
}
/**
@@ -134,9 +133,8 @@ public class SimpleFlow implements Flow, InitializingBean {
*/
@Override
public FlowExecution start(FlowExecutor executor) throws FlowExecutionException {
if (startState == null) {
initializeTransitions();
}
initializeTransitionsIfNotInitialized();
State state = startState;
String stateName = state.getName();
return resume(stateName, executor);
@@ -262,6 +260,12 @@ public class SimpleFlow implements Flow, InitializingBean {
return continued;
}
private synchronized void initializeTransitionsIfNotInitialized() {
if (startState == null) {
initializeTransitions();
}
}
/**
* Analyse the transitions provided and generate all the information needed to execute
* the flow.