encounter SqlTransactionRollbackException when complete a user task

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Member II

encounter SqlTransactionRollbackException when complete a user task

Hello,

    i have encountered an exception 'SqlTransactionRollbackException' when i invoked the API 'taskService.complete(Strin taskId,map variables)' to complete a User Task frequently; The probability of encountering this exception is high to 40%.The User Task's property 'asynchronous' is set by 'false',and 'exclusive' is 'true'.  what problem cause this exception? deadlock? WHY ?

SqlTransactionRollbackException

4 Replies
Highlighted
Alfresco Employee

Re: encounter SqlTransactionRollbackException when complete a user task

Have you had a look at this forum page - Deadlock in DB2 ?

If you could provide a bit more detail or even better a code example that might help. How are you invoking the rest call? Are choosing from a list at random, one at a time or in parallel and at what rate?

Highlighted
Member II

Re: encounter SqlTransactionRollbackException when complete a user task

First,thanks for your answer,Ryan!

        I have changed the db2 locktimeout to 60 sec according to the comment  on Deadlock in DB2 ,but it does't work.

my codes as below:

         //1.get task

        TaskEntity task = (TaskEntity) taskService.createTaskQuery().taskId(taskId).singleResult();
         if(task==null){
               throw new TimeException("this task has been finished");
         }

       //2.judge if have authority

     List<IdentityLink> linkList=taskService.getIdentityLinksForTask(taskId);
     boolean haveNotRight=true;
     if(linkList!=null){
          for(IdentityLink link:linkList){
                  if(approveUserId.equals(link.getUserId())){
                        haveNotRight=false;
                    }
            }
          }
       if(haveNotRight){
             throw new RunTimeException("no authority");
        }

      //3.get activiti variables map
      Map<String, Object> variables =taskService.getTaskVariablesByTaskId(taskId);
      ShareVO afterShareMain=(ShareVO)variables.get("afterShareMain");
      String serviceDataOfOrgCode=(String)variables.get("serviceDataOfOrgCode");

    //this api is to judge if the same net  base on the datas from db2
     Map<String,Object> isSame=this.isSameOrg(afterShareMain, serviceDataOfOrgCode);

    int isSameNet="1".equals(isSame.get("isSameNet"))?1:0;

     //4.put the parameter into the variables map

    variables.put("result", Integer.parseInt(result));
     variables.put("comments", comments);
     variables.put("approveUserId", approveUserId);

     variables.put("isSameNet",isSameNet);

    //5. set local  variable

     taskService.setVariablesLocal(taskId, variables);

    //6.complete the task
     taskService.completeTask(taskId, variables);

Besides,i have used a TaskListener when create this  UserTask(or act node),the TaskListener is to add candidate user to the UserTask( invoke the API 'DelegateTask.addCandidateUsers(String userId)').

   by the way,encouting the SqlTransactionRollbackException always happened when the number of visiting our soft web is higher.

Thanks! 

Highlighted
Member II

Re: encounter SqlTransactionRollbackException when complete a user task

forget your question Smiley Surprisedne at a time , not in parallel! Thanks!

Highlighted
Alfresco Employee

Re: encounter SqlTransactionRollbackException when complete a user task

Thanks for elaborating. Actually I should have also asked about your Activiti setup. It seems like what you're seeing could match to this issue:

deadlocked while deleting records from ACT_RU_EXECUTION with multiple activiti engines running