我们可以像这样挂起一个流程实例:

org.jbpm.process.instance.ProcessInstance processInstance = //...;
processInstance.setState(STATE_SUSPENDED);


并恢复它:

kieSession.getWorkItemManager().completeWorkItem(processInstance.getId(), params);


但这不起作用! ... 问题是什么?

谢谢。

最佳答案

要恢复流程,请使用processInstance.setState(ProcessInstance.STATE_ACTIVE)。 WorkItemManager在workItems(Web服务调用,人工任务,客户处理程序等)上而不是processInstances上进行操作。

尝试以下代码:

    KieSession ksession=......
    ProcessInstance processInstance = ksession.startProcess(......
    //suspend:
    SuspendProcessInstanceCommand susp=new SuspendProcessInstanceCommand();
    susp.setProcessInstanceId(processInstance.getId());
    ksession.execute(susp);
    //confirm suspended:
    assertEquals(ProcessInstance.STATE_SUSPENDED, ksession.getProcessInstance(processInstance.getId()).getState());

    //resume:
    ResumeProcessInstanceCommand res=new ResumeProcessInstanceCommand();
    res.setProcessInstanceId(processInstance.getId());
    ksession.execute(res);
    //confirm active:
    assertEquals(ProcessInstance.STATE_ACTIVE, ksession.getProcessInstance(processInstance.getId()).getState());

10-08 00:26