AnsweredAssumed Answered

Sending a message to cancel a usertask within same process

Question asked by jkuehn on Oct 8, 2013
Latest reply on Oct 9, 2013 by jkuehn
Hi,

we have a process with two usertasks spawning after a parallel gateway. As long as usertask 1 is not completed, the user should be able to complete usertask 2. Once usertask 1 is completed, usertask 2 should be removed.

How would you model this? Our current approach:

[img]http://picture.ms/images/2013/10/08/parallelUserMessagebTPsf.png[/img]

We try to solve it using a message. The problems we are having:
* Sending a message to usertask 2 with execution.getEngineServices().getRuntimeService().messageEventReceived(MESSAGE_NAME, executionIdOfUsertask2); from servicetask successfully ends usertask 2, calls "Do some stuff" and goes to the end event. But: the process will not be finished, "Send Message to Cancel Usertask " servicetask remains active.
* Sending a message to usertask 2 with execution.getEngineServices().getRuntimeService().messageEventReceived(MESSAGE_NAME, executionIdOfUsertask2); from servicetask in a seperate thread successfully cancels usertask 2 and finishes the process the desired way, but throws ActivitiOptimisticLockingException occasionally.

Catching ActivitiOptimisticLockingException didn't work. I tried to implement a retry loop as has been suggested in another discussion, but the catch clause doesn't catch ActivitiOptimisticLockingException:


int retries = 3;
while (retries > 0) {
    try {
        runtimeService.messageEventReceived(messageName, task.getExecutionId());
        break;
    } catch (ActivitiOptimisticLockingException ex) {
        if (–retries < 1) {
            // fatal, escalate
        }

        try {
            // give some time to recover, allow other instance to finish work on process
            Thread.sleep(100);
        } catch (InterruptedException e) {}
    }
}


Do you have some hints?

Thanks, greetings, Juri

Outcomes