最近在学习flowable,遇到了一个问题,就是当排他网关和并行网关同时使用的时候会出一个问题,特此记录一下,问题如下:
原来流程图是这样的:
1、启动流程,UT1完成任务并设置result=‘true’,然后UT3完成任务。
2、UT4完成任务
此时就会出现一个问题,就是流程走到并行网关的汇聚的地方的时候,流程就卡这不动了,如图
我理解的正常情况下,是应该汇聚完成后直接走到结束位置,然后整个流程结束,但是现实是卡到汇聚处了(也就是上图红色位置),然后我就觉得可能是因为在排它网关处又行程了两个流,导致框架识别的是这个并行网关应该是三个流汇聚才算完成,也就是说,只有UT2、UT3、UT4三个流都汇聚了之后才走结束。
然后我就试了下面的办法,如图:
再加一个排他网关,和并行网关的汇聚,然后让它按照条件汇聚即可,后经测试是可以的,但是具体是因为什么,也不太清楚,只是猜测,欢迎大佬指正。
贴一下测试代码和XML文件:
package com.lenovo.flowabledemo.controller;
import org.flowable.engine.*;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.junit.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ParallerExclusiveTest {
private static RuntimeService runtimeService;
private static TaskService taskService;
private static HistoryService historyService;
private static RepositoryService repositoryService;
private static ProcessEngineConfigurationImpl processEngineConfiguration;
private static ManagementService managementService;
private static DynamicBpmnService dynamicBpmnService;
static {
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
runtimeService = engine.getRuntimeService();
taskService = engine.getTaskService();
historyService = engine.getHistoryService();
repositoryService = engine.getRepositoryService();
processEngineConfiguration = (ProcessEngineConfigurationImpl) engine.getProcessEngineConfiguration();
managementService = engine.getManagementService();
dynamicBpmnService = engine.getDynamicBpmnService();
}
@Test
public void deploy(){
repositoryService.createDeployment()
.addClasspathResource("processes/ParallerExclusive2.bpmn")
.name("ParallelExclusive")
.deploy();
}
@Test
public void test01(){
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("parallerExclusive2");
String instanceId = processInstance.getId();
Task ut1 = taskService.createTaskQuery().processInstanceId(instanceId).taskAssignee("UT1").singleResult();
String taskId = ut1.getId();
Map map = new HashMap();
map.put("result","true");
taskService.complete(taskId,map);
Task ut3 = taskService.createTaskQuery().processInstanceId(instanceId).taskAssignee("UT2").singleResult();
taskService.complete(ut3.getId());
System.out.println("----------------------------------------"+instanceId);
}
@Test
public void test02(){
String instanceId = "272501";
Task ut4 = taskService.createTaskQuery().processInstanceId(instanceId).taskAssignee("UT4").singleResult();
String taskId = ut4.getId();
taskService.complete(taskId);
}
@Test
public void test03(){
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("parallerExclusive");
String instanceId = processInstance.getId();
Task ut1 = taskService.createTaskQuery().processInstanceId(instanceId).taskAssignee("UT1").singleResult();
String taskId = ut1.getId();
Map map = new HashMap();
map.put("result","true");
taskService.complete(taskId,map);
Task ut3 = taskService.createTaskQuery().processInstanceId(instanceId).taskAssignee("UT3").singleResult();
if(ut3==null){
System.out.println("-----------------ut3==null-----------------------");
}
System.out.println("-----------------instanceId-----------------------"+instanceId);
}
@Test
public void test04(){
String instanceId = "272501";
List<ProcessInstance> list = runtimeService.createProcessInstanceQuery().processInstanceId(instanceId).list();
System.out.println(list.size());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="parallerExclusive2" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="UT1" activiti:assignee="UT1"></userTask>
<userTask id="usertask2" name="UT2" activiti:assignee="UT2"></userTask>
<userTask id="usertask3" name="UT3" activiti:assignee="UT3"></userTask>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
<sequenceFlow id="flow1" sourceRef="usertask1" targetRef="exclusivegateway1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="exclusivegateway1" targetRef="usertask2">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${result=='true'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow3" sourceRef="exclusivegateway1" targetRef="usertask3">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${result=='false'}]]></conditionExpression>
</sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow4" sourceRef="usertask3" targetRef="parallelgateway2"></sequenceFlow>
<sequenceFlow id="flow5" sourceRef="usertask2" targetRef="parallelgateway3"></sequenceFlow>
<userTask id="usertask4" name="UT4" activiti:assignee="UT4"></userTask>
<parallelGateway id="parallelgateway1" name="Parallel Gateway"></parallelGateway>
<sequenceFlow id="flow6" sourceRef="startevent1" targetRef="parallelgateway1"></sequenceFlow>
<sequenceFlow id="flow7" sourceRef="parallelgateway1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow8" sourceRef="parallelgateway1" targetRef="usertask4"></sequenceFlow>
<parallelGateway id="parallelgateway2" name="Parallel Gateway"></parallelGateway>
<sequenceFlow id="flow10" sourceRef="parallelgateway2" targetRef="endevent1"></sequenceFlow>
<endEvent id="endevent2" name="End"></endEvent>
<exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway"></exclusiveGateway>
<sequenceFlow id="flow11" sourceRef="usertask4" targetRef="exclusivegateway2"></sequenceFlow>
<parallelGateway id="parallelgateway3" name="Parallel Gateway"></parallelGateway>
<sequenceFlow id="flow12" sourceRef="exclusivegateway2" targetRef="parallelgateway3">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${result=='true'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow13" sourceRef="exclusivegateway2" targetRef="parallelgateway2">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${result=='false'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow14" sourceRef="parallelgateway3" targetRef="endevent2"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_parallerExclusive2">
<bpmndi:BPMNPlane bpmnElement="parallerExclusive2" id="BPMNPlane_parallerExclusive2">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="90.0" y="356.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="310.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="590.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="105.0" x="590.0" y="346.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
<omgdc:Bounds height="40.0" width="40.0" x="460.0" y="268.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="1140.0" y="459.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
<omgdc:Bounds height="55.0" width="105.0" x="360.0" y="450.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1">
<omgdc:Bounds height="40.0" width="40.0" x="240.0" y="360.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway2" id="BPMNShape_parallelgateway2">
<omgdc:Bounds height="40.0" width="40.0" x="901.0" y="457.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
<omgdc:Bounds height="35.0" width="35.0" x="940.0" y="180.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="BPMNShape_exclusivegateway2">
<omgdc:Bounds height="40.0" width="40.0" x="660.0" y="454.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway3" id="BPMNShape_parallelgateway3">
<omgdc:Bounds height="40.0" width="40.0" x="870.0" y="290.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="415.0" y="287.0"></omgdi:waypoint>
<omgdi:waypoint x="460.0" y="288.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="480.0" y="268.0"></omgdi:waypoint>
<omgdi:waypoint x="480.0" y="177.0"></omgdi:waypoint>
<omgdi:waypoint x="590.0" y="177.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="480.0" y="308.0"></omgdi:waypoint>
<omgdi:waypoint x="480.0" y="373.0"></omgdi:waypoint>
<omgdi:waypoint x="590.0" y="373.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="642.0" y="401.0"></omgdi:waypoint>
<omgdi:waypoint x="921.0" y="457.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="642.0" y="205.0"></omgdi:waypoint>
<omgdi:waypoint x="890.0" y="290.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="125.0" y="373.0"></omgdi:waypoint>
<omgdi:waypoint x="240.0" y="380.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="260.0" y="360.0"></omgdi:waypoint>
<omgdi:waypoint x="260.0" y="287.0"></omgdi:waypoint>
<omgdi:waypoint x="310.0" y="287.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
<omgdi:waypoint x="260.0" y="400.0"></omgdi:waypoint>
<omgdi:waypoint x="260.0" y="477.0"></omgdi:waypoint>
<omgdi:waypoint x="360.0" y="477.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
<omgdi:waypoint x="941.0" y="477.0"></omgdi:waypoint>
<omgdi:waypoint x="1140.0" y="476.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
<omgdi:waypoint x="465.0" y="477.0"></omgdi:waypoint>
<omgdi:waypoint x="660.0" y="474.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12">
<omgdi:waypoint x="680.0" y="454.0"></omgdi:waypoint>
<omgdi:waypoint x="797.0" y="360.0"></omgdi:waypoint>
<omgdi:waypoint x="890.0" y="330.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
<omgdi:waypoint x="700.0" y="474.0"></omgdi:waypoint>
<omgdi:waypoint x="901.0" y="477.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14">
<omgdi:waypoint x="890.0" y="290.0"></omgdi:waypoint>
<omgdi:waypoint x="957.0" y="215.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>