jBPM - 在单独的线程中运行进程

时间:2015-09-09 08:56:07

标签: java multithreading jbpm

我正在尝试使用jBPM 6.2在单独的线程中运行jBPM进程。因此,我创建了一个名为WorkflowThread的类,并在每次需要运行新进程时启动一个新的工作流线程。该类的代码是:

public WorkflowThread(KieSession session, String workflowID, Map<String, Object> arguments) {
    this.session = session;
    this.workflowID = workflowID;
    this.arguments = arguments;
    this.workflowInstance = this.session.createProcessInstance(workflowID, arguments);
}

public void run(){
    if(this.workflowInstance.getState() == ProcessInstance.STATE_PENDING){
        this.session.startProcessInstance(this.workflowInstance.getId());
    }else{
        try {
            throw new Exception("The process with id "+this.workflowInstance.getId()+" is not pending but in state "+this.workflowInstance.getState());
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
        }
    }

}

主叫代码是:

WorkflowThread thread = new WorkflowThread(this.ksession, workflowID, arguments);
thread.start();

然而,尽管我在尝试启动它之前检查了进程的状态(我检查它还没有启动),但我得到了一个异常:

  

线程中的异常&#34;线程-1&#34; java.lang.IllegalArgumentException:流程实例只能启动一次       at org.jbpm.process.instance.impl.ProcessInstanceImpl.start(ProcessInstanceImpl.java:233)       在org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.start(WorkflowProcessInstanceImpl.java:389)       在org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:195)       at org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:204)       at org.drools.core.impl.StatefulKnowledgeSessionImpl.startProcessInstance(StatefulKnowledgeSessionImpl.java:1911)       at welcome.auth.workflowmanager.WorkflowThread.run(WorkflowThread.java:43)

我做错了什么?是否有可以使用的替代方法,以确保在单独的线程中执行工作流程?

1 个答案:

答案 0 :(得分:0)

假设jBPM sources你有STATE不匹配。这看起来像种族条件。但是,我没有jBPM的经验,所以也许我错了。