Getting OptimisticLocking exception the first time I try to claim a task

I’m accessing a Java EE Web application in two different browsers, trying to simulate a real situation.
From the first browser I start a process - in a @Transactional method of an @ApplicationScoped bean backend does:

processEngine.getRuntimeService().startProcessInstanceByKey(key, variables);

From the second browser I try to claim a task created by this process instance - in a @Transactional method of an @ApplicationScoped bean backend does:

processEngine.getTaskService().claim(taskId, userId);

And then I get the FlowableOptimisticLockingException:

Caused by: org.flowable.engine.common.api.FlowableOptimisticLockingException: Task[id=470044, name=Task name] was updated by another transaction concurrently at org.flowable.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:634) [flowable-engine-6.1.0.jar:6.1.0] at org.flowable.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:339) [flowable-engine-6.1.0.jar:6.1.0] at org.flowable.engine.common.impl.interceptor.AbstractCommandContext.flushSessions(AbstractCommandContext.java:179) [flowable-engine-common-6.1.0.jar:6.1.0] at org.flowable.engine.common.impl.interceptor.AbstractCommandContext.close(AbstractCommandContext.java:55) [flowable-engine-common-6.1.0.jar:6.1.0] at org.flowable.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:70) [flowable-engine-6.1.0.jar:6.1.0] at org.flowable.engine.impl.interceptor.JtaTransactionInterceptor.execute(JtaTransactionInterceptor.java:66) [flowable-engine-6.1.0.jar:6.1.0] at org.flowable.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:36) [flowable-engine-6.1.0.jar:6.1.0] at org.flowable.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56) [flowable-engine-6.1.0.jar:6.1.0] at org.flowable.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51) [flowable-engine-6.1.0.jar:6.1.0] at org.flowable.engine.impl.TaskServiceImpl.claim(TaskServiceImpl.java:179) [flowable-engine-6.1.0.jar:6.1.0]

I’m using the same processEngine, since it is thread-safe.

Could you reproduce the issue in the jUnit test please?
mvn archetype:generate -DarchetypeGroupId=org.flowable -DarchetypeArtifactId=flowable-archetype-unittest -DarchetypeVersion=6.0.1 -DgroupId=org.flowable -DartifactId=junittest

Hi @leandrocosta,

Could you share the process definition / BPMN XML as well? And could you share the @ApplicationScoped bean code as well?

Best regards,

Tijs

Thanks for your attention, bud I found out this was not the problem.

The problem is that I was make two parallel requests to backend, one of them was creating a new variable in the task scope, and the other one was claiming the task, and then, the first commited transaction worked fine, but the second one failed.

Hi @leandrocosta ,

Faced the same issue while running the workflows. Please try after running this query on your flowable database :

USE Flowable
ALTER DATABASE Flowable  
SET ALLOW_SNAPSHOT_ISOLATION ON  

ALTER DATABASE Flowable  
SET READ_COMMITTED_SNAPSHOT ON

Let me know, if it works for your case.

Thanks,
Divyesh