Relax sync in DefaultStateMachineService

- Now starting machine outside of a sycn block with
  acquire vs. release. This should allow long running
  start in a machine to allow next acquire to work faster.
- Forwardport #770
- Relates #777
This commit is contained in:
Janne Valkealahti
2019-12-25 07:40:26 +00:00
parent b456ea823a
commit 20c1f56381

View File

@@ -82,8 +82,10 @@ public class DefaultStateMachineService<S, E> implements StateMachineService<S,
@Override
public StateMachine<S, E> acquireStateMachine(String machineId, boolean start) {
log.info("Acquiring machine with id " + machineId);
StateMachine<S, E> stateMachine;
// naive sync to handle concurrency with release
synchronized (machines) {
StateMachine<S,E> stateMachine = machines.get(machineId);
stateMachine = machines.get(machineId);
if (stateMachine == null) {
log.info("Getting new machine from factory with id " + machineId);
stateMachine = stateMachineFactory.getStateMachine(machineId);
@@ -98,8 +100,9 @@ public class DefaultStateMachineService<S, E> implements StateMachineService<S,
}
machines.put(machineId, stateMachine);
}
return handleStart(stateMachine, start);
}
// handle start outside of sync as it might take some time and would block other machines acquire
return handleStart(stateMachine, start);
}
@Override