1 Reply Latest reply on Sep 8, 2009 4:18 PM by kukeltje

    [jBPM4] Behavior of tasks completion when inside two or more

      Hi everybody,

      Here is my problem:
      I do not understand the behavior of tasks completion when they are inside two or more forks. You will find the accurate questions in the test case comments.

      jBPM is not new for me, and I tried to understand my problem with the documentation and the forum. I am not sure whether this subject is already discussed for jBPM 4. If it is, please could you redirect me to the good thread?

      Thanks a lot for your help :)

      === Process ==================================

      <?xml version="1.0" encoding="UTF-8"?>
      <process key="test1" name="test1" xmlns="http://jbpm.org/4.0/jpdl">
       <start name="start1">
       <transition name="to fork1" to="fork1"/>
       </start>
       <fork name="fork1">
       <transition name="to task1" to="task1"/>
       <transition name="to task2" to="task2"/>
       </fork>
       <task name="task2">
       <transition name="to join2" to="join2"/>
       </task>
       <task name="task1">
       <transition name="to fork2" to="fork2"/>
       </task>
       <fork name="fork2">
       <transition name="to task1.1" to="task1.1"/>
       <transition name="to task1.2" to="task1.2"/>
       </fork>
       <taskname="task1.1">
       <transition name="to join1" to="join1"/>
       </task>
       <task name="task1.2">
       <transition name="to join1" to="join1"/>
       </task>
       <join name="join1">
       <transition name="to join2" to="join2"/>
       </join>
       <join name="join2">
       <transition name="to end1" to="end1"/>
       </join>
       <end name="end1"/>
      </process>
      


      === API ===================================
      // test case which extends JbpmTestCase
      public void testTaskConcurrency() {
       repositoryService.createDeployment().addResourceFromClasspath("test1.jpdl.xml").deploy();
      
       ProcessInstance processInstance = executionService.startProcessInstanceByKey("test1");
       String processInstanceId = processInstance.getId();
       System.out.println("Process started:");
       for (Task taskTemp : taskService.createTaskQuery().processInstanceId(processInstanceId).list()) {
       System.out.println(String.format("> Task '%s' with execution '%s'", taskTemp.getActivityName(), taskTemp.getExecutionId()));
       }
       /* Output (ok):
       * > Task 'task1' with execution 'test1.1.to task1'
       * > Task 'task2' with execution 'test1.1.to task2'
       */
      
       Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).activityName("task1").uniqueResult();
       taskService.completeTask(task.getId());
       System.out.println("task1 completed:");
       for (Task taskTemp : taskService.createTaskQuery().processInstanceId(processInstanceId).list()) {
       System.out.println(String.format("> Task '%s' with execution '%s'", taskTemp.getActivityName(), taskTemp.getExecutionId()));
       }
       /* Output (strange):
       * > Task 'task2' with execution 'test1.1.to task2'
       * > Task 'task1.1' with execution 'test1.1.to task1.1'
       * > Task 'task1.2' with execution 'test1.1.to task1.2'
       * > Task 'task1.1' with execution 'test1.1.to task1'
       */
       /* Questions:
       * Why do I have 2 different 'task1.1' (with different execution id)?
       * Which one should I complete?
       * Imagine task1 is not a task but a subprocess, this subprocess would be started twice. Is it normal?
       */
      
       // I cannot use the uniqueResult() method (the task I want to get is not unique)
       task = taskService.createTaskQuery().processInstanceId(processInstanceId).activityName("task1.1").list().get(0);
       taskService.completeTask(task.getId());
       System.out.println("task1.1 completed:");
       for (Task taskTemp : taskService.createTaskQuery().processInstanceId(processInstanceId).list()) {
       System.out.println(String.format("> Task '%s' with execution '%s'", taskTemp.getActivityName(), taskTemp.getExecutionId()));
       }
       /* Output (still strange):
       * > Task 'task2' with execution 'test1.1.to task2'
       * > Task 'task1.1' with execution 'test1.1.to task1.1'
       * > Task 'task1.2' with execution 'test1.1.to task1.2'
       */
      
       task = taskService.createTaskQuery().processInstanceId(processInstanceId).activityName("task1.2").uniqueResult();
       taskService.completeTask(task.getId());
       System.out.println("task1.2 completed:");
       for (Task taskTemp : taskService.createTaskQuery().processInstanceId(processInstanceId).list()) {
       System.out.println(String.format("> Task '%s' with execution '%s'", taskTemp.getActivityName(), taskTemp.getExecutionId()));
       }
       /* Output (still strange):
       * > Task 'task2' with execution 'test1.1.to task2'
       * > Task 'task1.1' with execution 'test1.1.to task1.1'
       */
       /* Question:
       * I reached the first join, why do I still see the second 'task1.1'?
       */
      
       task = taskService.createTaskQuery().processInstanceId(processInstanceId).activityName("task2").uniqueResult();
       taskService.completeTask(task.getId());
       System.out.println("task2 completed:");
       for (Task taskTemp : taskService.createTaskQuery().processInstanceId(processInstanceId).list()) {
       System.out.println(String.format("> Task '%s' with execution '%s'", taskTemp.getActivityName(), taskTemp.getExecutionId()));
       }
       /* Output (ok):
       * [nothing]
       */
      }
      


      === Environment ==============================
      - jBPM Version : 4.1
      - Database : MySQL 5.1
      - JDK : 1.6.0_15
      - Container : java -version
      - Configuration : default jbpm.cfg.xml
      - Libraries : default librairies