OptimisticLockingException when the user task is completed in parallel

I have a userTask that happens to be completed in parallel because of saved data on complete (It saves formValues on sub-process). This throw ‘OptimisticLockingException’ when the values in the form are saved from the userTask (each user Task has its values on the subprocess set to ‘null’, and when it’s completed they’re updated. But I don’t understand why Camunda considers that variables are same (because of the same variable name, i think) and updating on the same process but don’t consider that it’s subprocess variables).
What would be the solution to get rid of the exception when we also need the variable setting for the delegate following userTask.

Hello my friend! Welcome to community!

Yes, optimistic blocking happens because you are trying to update a variable with the same name 2 or more times at the same time, so the error is generated due to concurrency.

I didn’t understand the context very well, because maybe my level of “English” isn’t helping hehehe…

But I believe that if you generate this concurrent variable as a local variable using setVariableLocal(), this will resolve the issue.

I hope this helps!

William Robert Alves

1 Like

Hmm, if I understood correctly, you have the idea not to pass the these variables values to the ‘{taskId}/complete’ API, but to set them in the ‘complete’ execute listener (to create a listener and set the local variables in it)?

Do you want to explain to me better what you need to do? Maybe I didn’t understand very well… but if you explain what you need better, maybe together we can find a simple and functional solution for you!

Count on me! :facepunch: :grin:

1 Like

Hi @NERVO,

I think that when you create the variables as local beforehand (maybe with a listener or input mapping on the subprocess), the user task will handle them as local variables.

But it’s a long time ago when I have tried it.

Hope this helps, Ingo

3 Likes

Thanks, . I created a delegate in which variables are initialized and set it to ‘start’ execution listeners for ‘start event’ in sub process.

 execution.setLocalVariable('variable', null);

These variables I set them to output in userTask. Obtained variable value in next delegate after userTask ,there are no problems, exceptions, this is exactly what I wanted to achieve. Great work :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.