code: @Override
    public void recordProcessInstanceEnd(String processInstanceId, String deleteReason, String activityId) {
  
      if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().findById(processInstanceId);
  
        if (historicProcessInstance != null) {
          historicProcessInstance.markEnded(deleteReason);
          historicProcessInstance.setEndActivityId(activityId);
          
          // Fire event
          ActivitiEventDispatcher activitiEventDispatcher = getEventDispatcher();
          if (activitiEventDispatcher != null && activitiEventDispatcher.isEnabled()) {
            activitiEventDispatcher.dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_ENDED, historicProcessInstance));
          }
          
        }
      }
    }
docs: /*
  (non-Javadoc)
  
  @see org.activiti.engine.impl.history.HistoryManagerInterface# recordProcessInstanceEnd(java.lang.String, java.lang.String, java.lang.String)