My process isn't terminated even if has no tasks left


#1

Hi guys,
I have a little problem. There is a very simple single-path process definition finished with End Event (Terminate End Event).

My code fragment:
tasks = taskService.createTaskQuery()
.processInstanceId(processInstance.getId())
.list();
logger.info("Tasks: " + tasks.size());
logger.info("Is ended: " + processInstance.isEnded());

Output:
c.processRuntime.SimpleProcessRuntime : Tasks: 0
c.processRuntime.SimpleProcessRuntime : Is ended: false

I think I’ve finished all tasks associated with the process instance. The problem is that the process is not ended. What can be wrong?
Thanks.


#2

Hi @dikey94,

You may have to fetch the process instance again via RuntimeService#createProcessInstanceQuery. An object returned by the API is always a snapshot of the state when the call was made.

edit: or more precisely: if the instance is indeed finished, then the above query returns no value. Use the history service to access the historic process instance, if required.

Cheers,
Thorben


#3

Thanks. Is there any case when isEnded() method returns true?


#4

If you start a process instance and immediately completes, e.g. if it contains only service tasks and no asynchronous continuations.


#5

Understand. Thank you.

Regards.