How to know status of timer boundary event execution to avoid Optimistic Locking Exception

BPMN

I have message task which is waiting for message notification from rest API and on same task I have configured Timer Boundary Event which triggers after 5 min to perform a business operation.

After 5 minute, when timer boundry event triggers and starts performing business operation. Exactly at same time if we receive message correlation for message task then this meesage correlation completes message task and progresses execution to next service task until it reaches to next waiting task. When it reaches to waiting task then we are getting OptimisticLockingException and execution gets rollback to message task. Now operation performed inside service task is non-transactional hence system remains in inconsistent state.

We want prevent this scenario by validating if any job execution is in-progress or not. If any job execution in progress then we will not correlate message. Once job execution completes only then we will allow to correlate a message, so we can avoid optimistic locking exception and system will not perform any non-transactional operations.

Please guide how to check status of any job execution whether its execution is started or not

Would it help to suspend the rest of the process before processing your message and activate at the end? There might still be a race condition, if this isn’t time sensitive you might still want a delay there, or get a list of executions for your process instance to make sure there’s not another in progress.