4 Replies Latest reply on Oct 14, 2013 12:37 PM by ciberg

    Duplicate tasks created after completing previous task

    ciberg

      Hi, I have a web application using JBPM 5.4 and the processes have only human tasks.

       

      Sometimes when a task is completed JBPM creates the next task in the workflow in duplicate.

      It seems that this is aggravated when multiple users are using the application.

       

      This is the code that I use to complete a task:

       

                BlockingTaskOperationResponseHandler responseHandler = new BlockingTaskOperationResponseHandler();

                          try {

                                    Task task = taskService.getTask(taskId);

                                    TaskData taskData = task.getTaskData();

                                    humanTaskClient.complete(taskId, user, null, responseHandler);

                                    responseHandler.waitTillDone(75000);

                                    StatefulKnowledgeSession ksession = JBPMConnectionsInitializer.accessKnowledgeSession(processPackage);

                                    KnowledgeRuntimeLogger logger = JBPMConnectionsInitializer.activateKnowledgeRuntimeLog(ksession);

       

                                    new JPAWorkingMemoryDbLogger(ksession);

       

                                    ksession.getWorkItemManager().completeWorkItem(

                                                        taskData.getWorkItemId(), null);

                                    logger.close();

        ...

       

      This is the connection initializer:

                public static StatefulKnowledgeSession accessKnowledgeSession(String processPackage) throws Exception {

                          KnowledgeBase kbase = null;

                          StatefulKnowledgeSession ksession = null;

                          EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTANCE_ENTITY_NAME);

                          Environment env = KnowledgeBaseFactory.newEnvironment();

                          env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

                          kbase = readJbpmKnowledgeBase(processPackage);

                          ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);

                          CommandBasedHornetQWSHumanTaskHandler humanTaskHandler = new CommandBasedHornetQWSHumanTaskHandler(ksession);

                          humanTaskHandler.setConnection(HUMAN_TASK_SERVER_HOST, HUMAN_TASK_SERVER_PORT);

                ksession.getWorkItemManager().registerWorkItemHandler("Human Task",humanTaskHandler);

                          return ksession;

                }

       

       

      The tasks are started with this:

                          BlockingTaskOperationResponseHandler responseHandler = new BlockingTaskOperationResponseHandler();

                          try {

                                    humanTaskClient.start(taskId, user, responseHandler);

                                    responseHandler.waitTillDone(75000);

          ...

       

       

      Can you please tell me what is wrong and how can I solve this.

      Maybe this is happening because I'm not disposing of the ksession, but if I do that the application fails after completion of the task with a session not available error because it was disposed of.

        • 1. Re: Duplicate tasks created after completing previous task
          guilherme.telles

          I wish to know too.

           

          I'm also getting this error

          • 2. Re: Duplicate tasks created after completing previous task
            ciberg

            Still no one that can help on this?

            I still have this problem!!!!

            • 3. Re: Duplicate tasks created after completing previous task
              thomas.setiabudi

              Hi,

               

              I never got this problem before, and I do not know whether you use the default implementation of Work Item Handler for human task.

               

              But, assuming you use the default implementation of Human Task Work Item Handler,

              then I suppose this is what cause the problem:

               

              1. You called complete task function:

              humanTaskClient.complete(taskId, user, null, responseHandler);

              I think the default implementation of Human Task Work item handler, will set the task status to complete, and then call the completeWorkItem function.

               

              2. But, Then you manually still call the complete WorkItem:

              ksession.getWorkItemManager().completeWorkItem(

                                                                taskData.getWorkItemId(), null);

              This will trigger the complete workItem twice, thus making the next human task / any next node to be triggered twice.

               

              So I suggest trying to remove your code that calls completeWorkItem and let the Human Task Work Item handler to do that for you.

               

              Hope this helps.

               

              Regards,

              Thomas Setiabudi

              • 4. Re: Duplicate tasks created after completing previous task
                ciberg

                Thank you Thomas, your suggestion worked.

                 

                Sorry for the delay in my answer but I was involved in another work and only now I continued this one.