cancel
Showing results for 
Search instead for 
Did you mean: 

Count active process instances (no matter which process definition)

mgryszko
Champ in-the-making
Champ in-the-making
Is it possible to issue a query that will return a count of all process instances that are being executed?

I tried with:

runtimeService.createExecutionQuery().count()
runtimeService.createProcessInstanceQuery().count()


but I get always 0 as result, even if I know that at least one process is being executed.

Background of my question:
I'm in a functional test where I test the following:
- I send a JMS message with XML payload to a queue
- queue listener picks up the message, parses the XML and starts an Activiti process (service tasks only, no user interaction)
After the process is finished, I want to do some assertions. As the whole processing is done outside the current test thread, I have to deal with the asynchronicity.


2 REPLIES 2

fellowtom
Champ in-the-making
Champ in-the-making
Hi mgryszko,

I'm pretty new to activiti but I had a similar problem. I solved it by queuing with:

HistoryService historyService = processEngine.getHistoryService();
List<HistoricProcessInstance> hpiList =
    historyService.createHistoricProcessInstanceQuery().unfinished().list();
With this list you should get all the process instances which did not reached the end state yet. I used it to restart all my unfinished jobs.
I hope this is correct and helps you.

With kind regards,

FellowTom

trademak
Star Contributor
Star Contributor
The process instance query should be okay. But of course when the message is still being handled asynchronous the process instance could not be started yet. So you would need to implement a bit of polling logic to see when the process instance has been started. You can use the process instance query for that.

Best regards,