cancel
Showing results for 
Search instead for 
Did you mean: 

loopCardinality in multi instance subprocess unchecked

page80
Champ in-the-making
Champ in-the-making
I have a multi-instance, non-sequential, subpprocess that has an activiti:collection with (currently) two elements in it.

However, when setting multiInstanceLoopCharacteristics, I set the loopCardinality value to 5 (doing what have gleaned to mean a maximum of 5 instances/threads can run concurrently) and receive an exception when the two iterations conclude:


ERROR org.activiti.engine.impl.interceptor.CommandContext:close:140 - Error while closing command context
java.util.NoSuchElementException
        at java.util.AbstractList$Itr.next(AbstractList.java:350)
        at org.activiti.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.executeOriginalBehavior(MultiInstanceActivityBehavior.java:162)
        at org.activiti.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior.createInstances(ParallelMultiInstanceBehavior.java:82)
        at org.activiti.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.execute(MultiInstanceActivityBehavior.java:89)
        at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:45)


I tried adding a  <completionCondition>${nrOfCompletedInstances/nrOfInstances == 1 }</completionCondition> to make it break out forcefully even through the loop would have completed anyway, to no avail.

Only once I changed the loopCardinality to be <= the number of iterations being performed did it not error at the end of the process.  Either there is a misnomer about what loopCardinality is in relation to "instances" described in the user guide, or there is an issue with how the number of threads are being allocated.  I would feel that if it truly is a "maximum number of concurrent processes" then I should be able to define a number greater than the size of the iterator.  A maximum should not be constraining as a minimum.

Please let me know if I am interpreting these properties correctly and if this is a bug/valid complaint.

Thanks.
2 REPLIES 2

brianok
Champ in-the-making
Champ in-the-making
I'm not a BPMN expert but I thought loopCardinality is meant to "hardcode" the number of times to run the step and is not intended to have anything to do with iterating on collections.  Since activiti:collection is an Activiti extension, I would suspect that you are doing something that is unexpected.  I'm not sure there is a way to delegate Activiti to only use N threads of the thread pool.  There probably is a way to set the overall size of the thread pool, but I don't know what it is.

frederikherema1
Star Contributor
Star Contributor
The loopCardinality is NOT controlling how many threads are used, is controls EXACLTY how many times the Multi-instance activity will be executed (being either in a parallel execution or sequential). If you use this toghether with an activiti:collection (or loopDataInputRef), you should make sure the collection actually contains 5 (or more) elements.

If you're NOT sure the collection will contain 5 elements, use the completion-condition instead to check the loopCoonter is less than 5 and remove the loopCardinality declaration…