AnsweredAssumed Answered

Signal/Cancel running process

Question asked by mbonato on Aug 18, 2014
Latest reply on Aug 20, 2014 by jbarrez
I'm trying to find a good/suitable process design for a 'cancelable' process that involves some asynchronous tasks and a message receive task. The process may be simplified to the process shown in the following figure.

[img]http://snag.gy/BBBfQ.jpg[/img]

What makes things complicated is concurrency. The process is started in one thread, tasks are executed asynchronously in a background thread and the cancellation occurs in another thread.

First I thought about using a subprocess with a signal boundary event. This works as expected, as long as there is no concurrent access to the process. However, when the signal is send while task A is still executed the thread ends up in a optimistic looking exception when trying to commit the transaction. Unfortunately, task A also involves non-transactional actions. So I cannot rely on the transaction rollback, but need to know whether task A has started/completed. Synchronizing threads is not an option, since the application might be deployed on a cluster, with Activiti running on multiple JVMs.

My second thought, was to set a process variable and use exclusive gateways between the tasks. Setting a new process variable does not seem to end up in optimistic locking exceptions, so the tasks can finish normally. When a gateway is reached and the process has been canceled in the meanwhile, the execution diverts and rollback actions can be performed by another task. The drawback of this solution is, that if task B has already been reached and process execution waits for the message being received, I still need a signal to terminate it.

Any suggestions for more elegant solutions?

Outcomes