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

**URL:** <https://forum.flowable.org/t/getting-optimisticlocking-exception-the-first-time-i-try-to-claim-a-task/851>\
**Category:** Flowable Engine\
**Created:** [August 14, 2017, 1:09pm UTC](https://forum.flowable.org/t/getting-optimisticlocking-exception-the-first-time-i-try-to-claim-a-task/851 "2017-08-14T13:09:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leandrocosta](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/leandrocosta/32/258_2.png) [@leandrocosta](https://forum.flowable.org/u/leandrocosta)\
**Post date:** [August 14, 2017, 1:09pm UTC](https://forum.flowable.org/t/getting-optimisticlocking-exception-the-first-time-i-try-to-claim-a-task/851/1 "2017-08-14T13:09:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [August 15, 2017, 5:26am UTC](https://forum.flowable.org/t/getting-optimisticlocking-exception-the-first-time-i-try-to-claim-a-task/851/2 "2017-08-15T05:26:46Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![tijs](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tijs](https://forum.flowable.org/u/tijs)\
**Post date:** [August 15, 2017, 6:54am UTC](https://forum.flowable.org/t/getting-optimisticlocking-exception-the-first-time-i-try-to-claim-a-task/851/3 "2017-08-15T06:54:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![leandrocosta](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/leandrocosta/32/258_2.png) [@leandrocosta](https://forum.flowable.org/u/leandrocosta)\
**Post date:** [August 16, 2017, 10:50am UTC](https://forum.flowable.org/t/getting-optimisticlocking-exception-the-first-time-i-try-to-claim-a-task/851/4 "2017-08-16T10:50:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dvs\_Prajapati](https://avatars.discourse-cdn.com/v4/letter/d/d26b3c/32.png) [@Dvs\_Prajapati](https://forum.flowable.org/u/Dvs_Prajapati)\
**Post date:** [February 14, 2018, 5:55am UTC](https://forum.flowable.org/t/getting-optimisticlocking-exception-the-first-time-i-try-to-claim-a-task/851/5 "2018-02-14T05:55:54Z")

</div>

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
