怎样通过taskId取得流程实例

在jbpm4.0中的。我把executionId当作processInstanceId会不会出现问题?

//通过taskid取 流程实例
String executionId = pe.getTaskService().getTask(taskid).getExecutionId();
ProcessInstance processInstance = executionService.findProcessInstanceById(executionId);

如果不是这样写。应该怎么做?

String processInstanceId =

String processInstanceId = ""; ExecutionService executionService = processEngine.getExecutionService(); Execution execution = executionService.findExecutionById(executionId); // 得到流程实例(即主流程运行流向) Execution mainExecution = execution.getProcessInstance(); if (mainExecution == null) { processInstanceId = execution.getId(); } else { processInstanceId = mainExecution.getId(); } 这样应该可以得到。