0 Replies Latest reply on Oct 27, 2010 7:34 AM by Narciso Mazivila

    Deadlock executing TaskService.completeTask()

    Narciso Mazivila Newbie

      Hi,

       

      I am being victm of deadlocks when TaskService.completeTask() is executed.

       

      I use jBPM 4.3 with MS SQL SERVER 2005.

       

      Here goes the stack trace:


      org.hibernate.exception.LockAcquisitionException: could not delete: [org.jbpm.pvm.internal.task.SwimlaneImpl#1647413]
          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:82)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
          at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2541)
          at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2697)
          at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:74)
          at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
          at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
          at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:146)
          at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
          at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
          at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
          at org.jbpm.pvm.internal.tx.HibernateSessionResource.prepare(HibernateSessionResource.java:56)
          at org.jbpm.pvm.internal.tx.StandardTransaction.commit(StandardTransaction.java:107)
          at org.jbpm.pvm.internal.tx.StandardTransaction.complete(StandardTransaction.java:64)
          at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:61)
          at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
          at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
          at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
          at org.jbpm.pvm.internal.svc.SkipInterceptor.execute(SkipInterceptor.java:43)
          at org.jbpm.pvm.internal.svc.TaskServiceImpl.completeTask(TaskServiceImpl.java:96)
          at mz.solint.projg.bpm.ExecutionServiceImpl.completeTaskWork(ExecutionServiceImpl.java:192)
          at mz.solint.projg.bpm.ExecutionServiceImpl.completeTask(ExecutionServiceImpl.java:306)
          at sun.reflect.GeneratedMethodAccessor520.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
          at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
          at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
          at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.aspects.security.RunAsSecurityInterceptor.invoke(RunAsSecurityInterceptor.java:83)
          at org.jboss.ejb3.security.RunAsSecurityInterceptor.invoke(RunAsSecurityInterceptor.java:54)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:166)
          at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:115)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
          at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:240)
          at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
          at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
          at $Proxy252.completeTask(Unknown Source)
          at mz.solint.projg.rendering.component.panel.AbstractPanel.executeOutcome(AbstractPanel.java:686)
          at mz.solint.projg.rendering.component.action.OutcomeAction.execute(OutcomeAction.java:141)
          at mz.solint.projg.rendering.component.action.event.ExecuteActionEventListener.onEvent(ExecuteActionEventListener.java:49)
          at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:196)
          at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:140)
          at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1445)
          at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1229)
          at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1009)
          at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:549)
          at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:441)
          at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:449)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
          at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
          at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
          at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
          at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:437)
          at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:366)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
          at java.lang.Thread.run(Thread.java:619)
      Caused by: java.sql.SQLException: Transaction (Process ID 67) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
          at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
          at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
          at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
          at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:632)
          at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
          at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
          at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:506)
          at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:365)
          at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2523)
          ... 87 more

       

       

      You can find also the deadlock xdl file attached (open with SQL Server Management Studio).

       

      And here goes a piece of my code, I guess may help too.

       

       

      @Stateless
      @LocalBinding(jndiBinding = EjbUtil.JNDI_PREFIX + "ExecutionService")
      @RunAs("private")
      @SecurityDomain(mz.solint.projg.common.Constants.SECURITY_DOMAIN)
      public class ExecutionServiceImpl implements ExecutionService {
       ...
      
       private OperationResponse completeTaskWork(final Task task, final String outcome, final String comment) throws BPMException {
              final TaskService taskService = this.processEngine.getTaskService();
              final org.jbpm.api.ExecutionService executionService = this.processEngine.getExecutionService();
      
              OperationResponse operationResponse;
      
              final org.jbpm.api.task.Task jbpmTask = taskService.getTask(task.getId());
              final Execution processExecution = executionService.findExecutionById(jbpmTask.getExecutionId());
              final String processInstanceId = processExecution.getProcessInstance().getId();
              VariableContext variableContext = VariableContext.of(executionService, jbpmTask.getExecutionId());
              final Long processId = ProcessVariables.PROCESS_IDENTIFIER.getValue(variableContext);
              String taskName = jbpmTask.getName();
      
              // Save a record into [process_task_error] table signalling that this task is in error. This means that any
              // error, power outage or any other situation that invalidates the removal of the record will result in the task
              // needing to be unlocked, and the effects of the error reverted, by an administrator.
              BpmTaskOutcomeExecutionError startCompleteTaskError = this.executionServiceDao.startCompleteTask(processId, processInstanceId, taskName,
                      outcome);
      
              try {
                  // clean messages
                  ProcessVariables.EXECUTION_WARNINGS.setValue(variableContext, new ArrayList<String>());
                  ProcessVariables.EXECUTION_ERRORS.setValue(variableContext, new ArrayList<String>());
      
                  // Saving comments and extracting metadata MUST be done before task completes otherwise it will fail if it
                  // is the last task on the process.
                  final Document xmlObject = (Document) executionService.getVariable(jbpmTask.getExecutionId(), ProcessVariables.XML_OBJECT.getKeyName());
                  this.extractMetadataAssociatedWithTask(executionService, jbpmTask, xmlObject);
      
                  final TaskWorkareaMapping.Task workareaForTask = this.processService.getWorkareaForTask(processId, jbpmTask.getActivityName());
      
                  this.saveCommentIfApplicable(workareaForTask, processId, executionService, jbpmTask, comment, outcome);
      
                  this.executeTaskOutcomeActions(workareaForTask, executionService, jbpmTask, outcome);
      
                  JbpmTaskNames taskNames = this.executionServiceDao.getJbpmTaskNameAndSwimlaneName(jbpmTask.getId());
      
                  // remove the information about permissions for this task from the jBPM context map.
                  TaskPermissionCollection taskPermissions = ProcessVariables.TASK_PERMISSIONS
                          .getValue(variableContext, new TaskPermissionCollectionImpl());
                  if (StringUtils.isBlank(taskNames.getSwimlaneName())) {
                      taskPermissions.removeByTaskName(taskNames.getTaskName());
                      ProcessVariables.TASK_PERMISSIONS.setValue(variableContext, taskPermissions);
                  }
      
                  taskService.completeTask(task.getId(), outcome);
      
                  // remove the [process_task_error] record so that the task can continue to be executed.
                  this.executionServiceDao.removeCompleteTask(processInstanceId, taskName);
      
                  // Verify if necessary show work area.
                  operationResponse = this.getNextOperationResponseForProcess(processId, processInstanceId, jbpmTask.getAssignee());
              } catch (final Exception e) {
             ...
             }
       }    
      
       ...
      
      }
      

       

       

      Any help please?

       

      Thanks!!!