Number of tokens vs number of executions

Hello, I have the following BPMN

when I deploy and start it, I see the following in the cockpit

as I had imagined, there are two tokens waiting for the tasks to complete.

I am surprised that when running programmatic tests against this I see 6 executions instead of two.

The code is

  final ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESS_KEY);
  ProcessInstanceAssert piAssert = assertThat(processInstance);
 Assertions.assertEquals(2, runtimeService.createExecutionQuery()
                .count(), "should have 2 active executions");

and it fails with

org.opentest4j.AssertionFailedError: should have 2 active executions ==> 
Expected :2
Actual   :6

I thought that tokens correspond to executions, but it’s apparently not the case.

What are these six executions? Is there any way to write a test that would confirm that I have 2 “tokens” active?


maybe I shouldn’t care about executions at all, but use activity instances instead? (see Introducing an Activity Instance Model to the core Process Engine | Camunda )

Hi @User9,

For testing purposes, it is a good idea.

If you want to have a closer look behind the scenes of executions, this chapter is a good starting point:

The Subprocess, the Parallel Gateway and the Call Activities spawn new executions as well.

Hope this helps, Ingo

Thanks @Ingo_Richtsmeier .

I also see in Introducing an Activity Instance Model to the core Process Engine | Camunda that execution Ids should never be used for message correlations, which is what I wanted to do.

Unfortunately I see that the testing framework lacks the ability to query the activity instances, and I’m not sure if it’s because of design considerations, or simply nobody has implemented that yet.

Hello my friend!

I didn’t quite understand what you need, but if you need, for example, to check the amount of instances in ALL processes, including those running within “calls activitys”, you can use “processInstanceQuery().count( )”.

But if you need to filter the instance count by one or more specific processes, you can filter as follows:


William Robert Alves

Hello, thanks for being so active on this forum!

I think you are correct. After checking on the cockpit there are indeed three separate process instances, and your suggestion returns the correct number.

1 Like

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