Skip to content

Multi threading issue in spring-statemachine-core 2.2.0.RELEASE , No thread safety in statemachine #2

@kravi1234

Description

@kravi1234

we have observed one thread for statemachine is getting impacted because of others and is getting stopped abruptly. for this we needed to make a lock on every state changes for that statemachine.

Do we alternative solution here ? can statemachine provide thread safety here ?

code snippet

@component
@slf4j
public class TicketStateHandler extends LifecycleObjectSupport{
private final Lock lock;

private void handleEvent(Message event, TicketStatus sourceState) {
lock.lock();
try {
stateMachine.stop();
stateMachine
.getStateMachineAccessor()
.doWithAllRegions(
access ->
access.resetStateMachine(
new DefaultStateMachineContext<>(sourceState, null, null, null)));
stateMachine.start();
boolean accepted = stateMachine.sendEvent(event);
if (!accepted) {
throw new InvalidBookingStateTrasitionException(
"Invalid Ticket State Transition error. Current Ticket State is "
+ sourceState.toString(),
new ExceptionMessages(ErrorCodes.ERR2103.toString(), sourceState.toString()));
}
log.info("Exit handleEvent()");
} finally {
lock.unlock();
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions