Why I can search the same process instance by runtimeService and historyService at same time?

I have two process instance and thats not been ended. But i can search them by runtimeService and historyService. At the before I think just the ended process instance can searched by the hisotryService. I am wrong or the camunda wrong?

Here is my code

   public ResponseEntity<Map<String, Object>> getRecords(PageAndSize pageAndSize) {
        User user = userService.getCurrentUser();
        List<ProcessInstance> instances = runtimeService.
                createProcessInstanceQuery()
                .variableValueEquals(
                        SignUpProjectProcessCommonConstants.
                                VAR_APPLICANT_ID,
                        String.valueOf(user.getId())
                ).list();

        List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery()
                .variableValueEquals(
                        SignUpProjectProcessCommonConstants.
                                VAR_APPLICANT_ID,
                        String.valueOf(user.getId())
                ).list();

        List<String> ids = instances.stream().map(Execution::getId).collect(Collectors.toList());
        ids.addAll(historicProcessInstances.stream().map(HistoricProcessInstance::getId).collect(Collectors.toList()));
        List<ProjectApplicationRecord2VO> voList = toVO(ids, false);
        Page page = PageableUtil.getPage(pageAndSize, voList);
        return new ResponseEntity<>(PageableUtil.resolvePage(page), HttpStatus.OK);
    }

And here is the process instances

Please help me. Thanks you all.

Is the historyService can both search the running and finished process instances ?

Think of it like this: stunning instance waiting in a task already has a history as well, at least one start event has been passed already , and this is logged by the history service.

So running instanced ca be found by runtime and history service.
Ended instances only by history service.

2 Likes

Thank you for your answer.