MultiInstance collection expression(function) executes multiple times

Lets say I have a multi instance subprocess:

<subProcess id="random_subprocess" name="Random subProcess">
                <multiInstanceLoopCharacteristics isSequential="false" flowable:collection="${initialize.getRandomList(execution)}" flowable:elementVariable="randomElement"></multiInstancethisLoopCharacteristics>
                ...
                ...
                ...
</subProcess>

While debugging, I notice that this function initialize.getRandomList(execution) is executed (n+1) times where n is the size of the list returned by this function. It returns the same list (size n) on each re-execution.

Ideally, the function should have been called only once. I may be missing out something here. I am looking out if anyone can help me fix this. I am not in favour of pre-computing the function value and storing it as a process/task variable.

Haven’t checked the code, but my guess: it gets called every time when the subprocess is completed to check if all needed instances have been completed or there’s still some running.

1 Like

@joram Thanks for clarification.