1 Reply Latest reply on Mar 24, 2014 2:42 AM by Maciej Swiderski

    Row has been updated or deleted by an

    mvermand Newbie



      I have an issue with concurrent access of a ProcessInstance.

      I reduced the issue to the following situation:


      The "Long Running Task" is now a Thread.sleep(10000);

      The "Wait to proceed" node is an event node.


      So a processInstance is started with ksession.startProcessInstance(instanceId) in thread 1.

      It kicks off the "Long Running Task" and registers the event node.


      Then, a REST service message arrives and some java code is run in a second thread.

      In this thread a new ksession is created and a signalEvent is issued upon this ksession.


      Everything ok so far.


      Then, after 10 seconds, the Long Running Task ends and the ksession tries to persist ProcessInstanceInfo object.

      This throws  org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [org.jbpm.persistence.processinstance.ProcessInstanceInfo#24483].


      I think I do understand why this happens, but I'm not quite sure how to resolve.


      1) Should I somehow reuse the ksession from the first thread to send the signalEvent?

      2) If so, how to handle a "clustered" environment?  The processInstance can be started on node 1 and the REST message can arrive on node 2.

      At that point it is not possible to reuse the ksession object.  The loadbalancer has no knowledge of what session is running on which node so the REST request can end up on any of the two nodes (the initial processStart was not started via a REST request).





        • 1. Re: Row has been updated or deleted by an
          Maciej Swiderski Master

          the main issue here is that you keep the process instance sort of locked (loaded from db but not written) while the thread sleep is blocking the thread. And thus while this is released you try to save process instance (loaded 10 secs ago) but it was already updated in meantime by the signal operation.


          To resolve it, you need to execute the thread sleep as an async operation which means it will release the process instance and fetch it again when you're done with async processing by completing Workitem. Check docs about asynchronous operations for available options for such execution.