cancel
Showing results for 
Search instead for 
Did you mean: 

Detect ended process instance

dibrandt
Champ in-the-making
Champ in-the-making
Hello,

we use this method to detect a ended process instance.
We call the method after the engine fired an event at the end event node.
Is this the best method to detect a ended instance? Is the List<Execution> always empty?  Or exists a other solution?


    public void detectProcStatusFromActivity() {
        if(this.status == null) {
            if (this.processInstanceId == null) {
                LOG.debug("Could not detect processState without processInstanceId");
            } else {
   
                try {
                    List<Execution> executions = getActivitiRuntimeService().createExecutionQuery()
                            .processInstanceId(this.processInstanceId).list();
                    if (executions.isEmpty()) {
                        this.status = ProcStatus.CLOSED;
                    }
                } catch (ActivitiException e) {
                    LOG.debug(
                            "Exception while trying to find Activiti process instance for instanceId {}, " +
                            "assuming new process state: CLOSED.",  processInstanceId, e);
                    this.status = ProcStatus.CLOSED;
                }
            }
        }
    }

1 REPLY 1

trademak
Star Contributor
Star Contributor
That's one way to do it. Another way is to query for process instances with a specific process instance id. Because when a process instance is ended it's removed from the runtime process instance table and moved to the history. So this query needs to return an empty list as well.

Best regards,