AnsweredAssumed Answered

Don't allow same task to be completed by different user at same time

Question asked by himanshu.agarwal on Nov 11, 2016
Latest reply on Nov 14, 2016 by vasile.dirla
Hey guys,

I want to implement optimistic locking kind of behavior (I know its already been built in), but not sure why this is not working, adding error below. I have a requirement where a task is available in a pool and two users may complete the task at the same time and we need to send error back to the user whose transaction is executed secondly but I get deadlock error rather than task not available or Optmistic locking exception.

Database level isolation level

TX_ISOLATION - REPEATABLE-READ


### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
### The error may involve org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity.updateHistoricTaskInstance-Inline
### The error occurred while setting parameters
### SQL: update ACT_HI_TASKINST set       EXECUTION_ID_ = ?,       NAME_ = ?,       PARENT_TASK_ID_ = ?,       DESCRIPTION_ = ?,       OWNER_ = ?,       ASSIGNEE_ = ?,       CLAIM_TIME_ = ?,       END_TIME_ = ?,       DURATION_ = ?,       DELETE_REASON_ = ?,       TASK_DEF_KEY_ = ?,       FORM_KEY_ = ?,       PRIORITY_ = ?,       DUE_DATE_ = ?,       CATEGORY_ = ?     where ID_ = ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
   at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
   at com.mysql.jdbc.Util.getInstance(Util.java:387)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:950)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
   at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
   at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:41)
   at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:66)
   at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:45)
   at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:100)
   at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:148)
   at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:870)
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:611)
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:211)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:137)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:66)
   at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47)
   at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
   at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
   at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
   at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
   at org.activiti.engine.impl.TaskServiceImpl.claim(TaskServiceImpl.java:167)
   at com.shutterfly.eni.service.impl.ActivitiServiceImpl.claimAndCompleteTask(ActivitiServiceImpl.java:73)
   at com.shutterfly.eni.service.impl.OrderServiceImpl.submitSbsPlatformOrder(OrderServiceImpl.java:926)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
   at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)


Appreciate, your prompt response.

-Himanshu

Outcomes