AnsweredAssumed Answered

Multi-Instance's completionCondition method executed twice

Question asked by wangsenyuan on Jan 11, 2016
Latest reply on Jan 20, 2016 by jbarrez
I am learning activiti, and following is a code snippet to test multi-instance task;


<scriptTask id="scripttask1" name="Script Task" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <multiInstanceLoopCharacteristics isSequential="true">
         <loopCardinality>100</loopCardinality>
        <completionCondition>
               ${processHelper.shouldStop(currentIndex)}
            </completionCondition>
      </multiInstanceLoopCharacteristics>
      <script>
            execution.setVariable("" + currentIndex, currentIndex *
            currentIndex)
            execution.setVariable("currentIndex", currentIndex + 1)
         </script>
    </scriptTask>

There is no special, but just use a helper method to determine whether to finish the task or not; following is the method:

        public boolean shouldStop(int index) {
      System.out.println("shouldStop called with [" + index + "]");
      return index >= 10;
   }

It is indeed called that method with every index, from 0 to 10; but, one strange thing I noticed is, two execution made for each index, following is the output:
shouldStop called with [1]
shouldStop called with [1]
shouldStop called with [2]
shouldStop called with [2]
shouldStop called with [3]
shouldStop called with [3]
shouldStop called with [4]
shouldStop called with [4]
shouldStop called with [5]
shouldStop called with [5]
shouldStop called with [6]
shouldStop called with [6]
shouldStop called with [7]
shouldStop called with [7]
shouldStop called with [8]
shouldStop called with [8]
shouldStop called with [9]
shouldStop called with [9]
shouldStop called with [10]
shouldStop called with [10]

It seems no harm yet, however, I just want to know, is this the expected behaviour and is there any way to avoid the second invocation?

Thanks.

Outcomes