Flowable6.6.0排他网关和并行网关同时使用的问题

最近在学习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>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
Flowable是一个开源的业务流程管理引擎,网关Flowable中一种常用的网关类型,用于在业务流程中进行条件分支。 网关通过判断分支条件来选择只满足条件的一条路径进行流程流转。在Flowable中,可以通过XML或者Java代码配置网关的条件和分支路径。 配置网关时,需要先定义网关节点,并设置节点的唯一标识。然后,通过设置网关节点的出口条件,来定义网关的分支条件。 在XML配置中,可以使用<sequenceFlow>元素来设置分支条件。每个<sequenceFlow>元素都可以设置一个条件表达式,用来判断该分支是否符合条件。条件表达式可以使用Flowable提供的表达式语言,如${var == 1}或${var > 10}。 在Java代码配置中,可以使用Flowable提供的API来设置分支条件。通过调用org.flowable.bpmn.model.SequenceFlow类的条件方法来设置条件表达式,如sequenceFlow.setConditionExpression("${var == 1}")。 配置网关时,还可以设置默认的分支路径。当所有的分支条件均不满足时,流程就会沿着设置的默认路径进行流转。设置默认路径时,只需要在<sequenceFlow>元素的条件中不写表达式即可。 网关在流程运行时的行为是,首先会根据各个分支条件表达式的结果进行判断,确定满足条件的分支。然后,仅选择满足条件的一条路径,并根据该路径的出口流转至下一个节点。 总之,网关Flowable中一种常用的网关类型,用于根据条件进行业务流程的分支判断和流转。通过XML或Java代码配置分支条件和默认路径,可以实现业务流程的灵活控制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值