setLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES, 0);
setLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES, nrOfInstances);
List<ActivityExecution> concurrentExecutions = new ArrayList<ActivityExecution>();
for (int loopCounter=0; loopCounter<nrOfInstances; loopCounter++) {
ActivityExecution concurrentExecution = execution.createExecution();
concurrentExecution.setActive(true);
concurrentExecution.setConcurrent(true);
concurrentExecution.setScope(false);
// In case of an embedded subprocess, and extra child execution is required
// Otherwise, all child executions would end up under the same parent,
// without any differentiation to which embedded subprocess they belong
if (isExtraScopeNeeded()) {
ActivityExecution extraScopedExecution = concurrentExecution.createExecution();
extraScopedExecution.setActive(true);
extraScopedExecution.setConcurrent(false);
extraScopedExecution.setScope(true);
concurrentExecution = extraScopedExecution;
}
concurrentExecutions.add(concurrentExecution);
logLoopDetails(concurrentExecution, "initialized", loopCounter, 0, nrOfInstances, nrOfInstances);
}
// Before the activities are executed, all executions MUST be created up front
// Do not try to merge this loop with the previous one, as it will lead to bugs,
// due to possible child execution pruning.
for (int loopCounter=0; loopCounter<nrOfInstances; loopCounter++) {
ActivityExecution concurrentExecution = concurrentExecutions.get(loopCounter);
// executions can be inactive, if instances are all automatics (no-waitstate)
// and completionCondition has been met in the meantime
if (concurrentExecution.isActive() && !concurrentExecution.isEnded()
&& concurrentExecution.getParent().isActive()
&& !concurrentExecution.getParent().isEnded()) {
setLoopVariable(concurrentExecution, getCollectionElementIndexVariable(), loopCounter);
executeOriginalBehavior(concurrentExecution, loopCounter);
}
}