4 Replies Latest reply on Oct 14, 2013 12:37 PM by João Guerra

    Duplicate tasks created after completing previous task

    João Guerra Newbie

      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.