AnsweredAssumed Answered

multiInstanceCharacteristics - Sequential Execution Issue

Question asked by jagathvijayan on May 3, 2011
Latest reply on May 4, 2011 by jagathvijayan
For sequential executions (isSequential="true"), only the first value from the collection gets assigned to all the executions.  For parallel executions (isSequential="false"), it works fine and each execution gets one value from the collection.

Here's the snippet:

    <serviceTask id="servicetask1" name="Serial Multi Task" activiti:class="com.activity.test.SerialMultiDelegate" activiti:assignee="${item}">
       <multiInstanceLoopCharacteristics isSequential="false" activiti:collection="${items}" activiti:elementVariable="item" />
    </serviceTask>

public class SerialMultiDelegate implements JavaDelegate {

   @Override
   public void execute(DelegateExecution execution) throws Exception {
      String item = (String) execution.getVariable("item");
      Thread.sleep((System.currentTimeMillis() % 5) * 1000);
      System.out.println("Item: " + item);
   }

}

public class SerialMultiRunner {

   public static void main(String[] args) {
      ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
      RepositoryService repositoryService = processEngine
         .getRepositoryService();
      repositoryService.createDeployment().addClasspathResource(
            "diagrams/SerialMulti.bpmn20.xml")
            .deploy();
      RuntimeService runtimeService = processEngine.getRuntimeService();
      Collection<String> items = new ArrayList<String>();
      items.add("East");
      items.add("West");
      items.add("North");
      items.add("South");
      Map<String, Object> processVariables = new HashMap<String, Object>();
      processVariables.put("items", items);
      runtimeService.startProcessInstanceByKey("SerialMulti",
            processVariables);
   }

}

Output (When isSequential="true")

Item: East
Item: East
Item: East
Item: East

Output (When isSequential="false")

Item: East
Item: West
Item: North
Item: South

Has anyone encountered a similar issue? Is this a bug or expected behavior?

Outcomes