AnsweredAssumed Answered

Parallel multi instance usertasks collection from service

Question asked by mindaugas on Aug 22, 2012
Latest reply on Aug 23, 2012 by mindaugas
The example: (from
<userTask id="miTasks" name="My Task" activiti:assignee="${assignee}">
  <multiInstanceLoopCharacteristics isSequential="true"
     activiti:collection="${myService.resolveUsersForTask()}" activiti:elementVariable="assignee" >

The problem is that service "myService" method resolveUsersForTask are invoked multi-times.

In activiti-engine class method: org.activiti.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior.createInstances evaluate expresion values multi-times.

First resolving:
int nrOfInstances = resolveNrOfInstances(execution);

Second only for setting assignee (string value from collection) are invoked collectionExpression (myService.resolveUsersForTask()):

    for (int loopCounter=0; loopCounter<nrOfInstances; loopCounter++) {
        executeOriginalBehavior(concurrentExecution, loopCounter);

So totally this service are invoked collection.size()+1 times. May be in near future possible optimize this part?