gpt4 book ai didi

java - 如何查询流程定义的运行实例?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:52:01 25 4
gpt4 key购买 nike

camunda引擎是否提供API来查询某个进程的所有运行实例?此查询是否也包括暂停的实例?

最佳答案

您可以使用以下代码查询一个进程的所有正在运行的进程实例:

package org.camunda.bpm;

import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import java.util.List;

public class AllRunningProcessInstances {

public List<ProcessInstance> getAllRunningProcessInstances(String processDefinitionName) {
// get process engine and services
ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();

// query for latest process definition with given name
ProcessDefinition myProcessDefinition =
repositoryService.createProcessDefinitionQuery()
.processDefinitionName(processDefinitionName)
.latestVersion()
.singleResult();

// list all running/unsuspended instances of the process
List<ProcessInstance> processInstances =
runtimeService.createProcessInstanceQuery()
.processDefinitionId(myProcessDefinition.getId())
.active() // we only want the unsuspended process instances
.list();

return processInstances;
}

}

如果您甚至想包含暂停的流程实例,则只需删除 .active() 行即可。

关于java - 如何查询流程定义的运行实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23269094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com