cancel
Showing results for 
Search instead for 
Did you mean: 

How to avoid multiple instances of the same process

jaylemur
Champ in-the-making
Champ in-the-making
Hi !

I have several activiti engines embeeded in several JVMs sharing the same DB.

How is the best way to avoid starting an other instance of a specific process if one is already started ?

Thanks in advance

Cheers,
Patrick Brühlmann
2 REPLIES 2

frederikherema1
Star Contributor
Star Contributor
There is nothing built in to prevent this, because it's 100% acceptable to start multiple instances of a single process. If you want to have only a single process-instance of a process, you'll have to come up with a mechanism yourself to prevent this from happening, leveraging the DB.

One way of accomplishing this is to add a "receive" event (or message-event) after the none-start event of the process you want to have only one instance of. One machine starts the process in advance, having one process running of that type.

Then, the other machines (how like to start the process) simply signal that process (or message). In case the process is the first one doing this, the process will continue. In case another machine does the same thing at almost the same time, it will get an optimisticLockException from activiti, due to the fact the process is already signaled from another transactions. All machines that want to do this afterwards, will get an exception saying the process cannot be signaled.

frederikherema1
Star Contributor
Star Contributor
There is nothing built in to prevent this, because it's 100% acceptable to start multiple instances of a single process. If you want to have only a single process-instance of a process, you'll have to come up with a mechanism yourself to prevent this from happening, leveraging the DB.

One way of accomplishing this is to add a "receive" event (or message-event) after the none-start event of the process you want to have only one instance of. One machine starts the process in advance, having one process running of that type.

Then, the other machines (how like to start the process) simply signal that process (or message). In case the process is the first one doing this, the process will continue. In case another machine does the same thing at almost the same time, it will get an optimisticLockException from activiti, due to the fact the process is already signaled from another transactions. All machines that want to do this afterwards, will get an exception saying the process cannot be signaled.