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.