cancel
Showing results for 
Search instead for 
Did you mean: 

Multi-Instance's completionCondition method executed twice

wangsenyuan
Champ in-the-making
Champ in-the-making
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.
2 REPLIES 2

wangsenyuan
Champ in-the-making
Champ in-the-making
The first question for activiti

jbarrez
Star Contributor
Star Contributor
I believe the condition could indeed be called twice, depending on its usage. As you say, no real harm is done.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.