Number of tokens on multi-instance task

Hello,

I have a multi-instance service task that runs 3 times. After completing 1 of the 3 instances, I was expecting the number of tokens to decrease to 2 but it still shows 3 blue tokens
runtime

However, when I check the history view, it shows only two blue tokens
history

Is this expected or am I missing something? I wanted to ask the reasoning behind this or if there is better way to see at runtime only the number of running instances without including the completed ones.

Thanks

Hello my friend!

When you run a multi-instance, some variables are created to control this mechanism and you can see them when clicking on the root instance.

As you can see in the image, there is a variable created called “nrOfActiveInstances” that tells you how many instances of this multi-instance are still running.

Below is what each variable means:

  • loopCounter = counts how many loops the multi-instance has already executed.

  • nrOfActiveInstance = counts how many instances are still active in this multi-instance.

  • nrOfCompletedInstances = counts how many instances have already been completed by the multi-instance.

  • nrOfInstance = counts the number of total instances of this multi-instance.

Hope this helps.

William Robert Alves

1 Like

Hi @WilliamR.Alves

Thanks for your reply. I see those variable

The question I have is, why do I see 3 tokens while nOfActiveInstances is 2?

This happens because an instance of a multi-instance does not create several sub-instances… but rather creates several “executions” of the same instance… so the token value that you see on the Camunda front page refers to the number of executions that will be performed for that instance…

This means that the number that you see on the front page refers to the “nrOfInstances” variable.

Multi-instance it’s basically like “running a for loop” on an array of instances.

William Robert Alves

Thanks for the clarification.

I also observed that at the process definition level, it shows nOfActiveInstances not nrOfInstances, which looks a bit confusing to me

Below I’m leaving a link to the official Camunda documentation that explains more about multi-instance, perhaps it will help you understand better.

William Robert Alves

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.