I came across an unexpected optimistic locking exception with parallel execution. In a test process, I can use a fork and join, asynchronous, non exclusive execution and the parallelism works as expected.
However, if I create a process variable in each of the parallel flows, I get an optimistic locking exception. Its as if setting independent variables somehow binds the executions together. This is unexpected and leads to some interesting consequence in terms of repeating activities.
Is this a bug?
Please find attached a simple scripted process. Note this has the addition of some async noOps to really reinforce the point.
do you set any variable when you start the process? Does the behavior change if you do so?
I’m asking because ExecutionEntity has a field cachedEntityState that is also reflected in a database attribute. This field is a bitmap that encodes if an execution has variables, event subscriptions, jobs, etc. This is an optimization to avoid certain database queries. However, the impact is that setting the first variable will flip a bit in this map and therefore, two transactions setting two (different) variables in parallel may result in OptimisticLockingException.
Hi Thorben,
No variable is set at the start. So it seems there is consequence to non exclusive parallel execution. As long as you dont set process level variables its fine. However to propagate up from local to process scope could be tricky…
two different variable names, each one set on a different path. (Ive attached a very simple minimal example in the original post - its classless so easy to deploy if you want to play…)
Thanks for the elaboration. My issue is now solved. So lots of credits to you.
Actually I can set any variable at process level to get this working. It does not need to be the same variables that are set during execution. A thing not to overlook, is that the joining gateway must be set to exclusive, otherwise it sometimes still fails with the optimistic lock exception when testing with multiple (50) test processes at the same time. With the exclusive lock all tests run fine so far.