并行网关允许将流程分成多条分支,也可以把多条分支汇聚在一起,并行网关的功能是基于进入和外出顺序流的;
fork分支:
并行后的所有外出顺序流,为每个顺序流都创建一个并发分支;
join汇聚:
所有达到并行网关,在此等待的进入分支,直到所有进入顺序的分支都达到以后,流程就会通过汇聚网关
注意:如果同一个并行网关有多个进入和多个外出顺序流,它就同时具有分支和汇聚功能;这时,网关会先汇聚所有进入的顺序流,然后切分成多个并行分支;
与其他网关的主要区别是,并行网关不会解析条件;及时顺序流中定义了条件,也会被忽略;
package com.wn.Par;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
/*流程部署*/
public class Deployment {
public static void main(String[] args) {
//获取ProcessEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//获取RepositoryService对象进行流程部署
RepositoryService repositoryService = processEngine.getRepositoryService();
//进行部署,将对应的流程定义文件生成到数据库当中,作为记录进行保存
org.activiti.engine.repository.Deployment deployment= repositoryService.createDeployment()
.addClasspathResource("bpmnfile/hoildayPar.bpmn") //加载流程文件
.addClasspathResource("bpmnfile/hoildayPar.png")
.name("请假流程-并行网关") //设置流程名称
.key("hoildayPar-Key")
.deploy();//部署
//输出部署信息
System.out.println("流程名称:"+deployment.getName());
System.out.println("流程ID:"+deployment.getId());
System.out.println("流程key:"+deployment.getKey());
}
}
package com.wn.Par;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import java.util.HashMap;
import java.util.Map;
/*启动流程实例*/
/*设置流程变量的值*/
public class StartInstance {
public static void main(String[] args) {
//获取ProcessEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//获取RuntimeService
RuntimeService runtimeService = processEngine.getRuntimeService();
//设置流程变量 启动流程时设置
//定义一个map集合,存放assignee的值
Map<String ,Object> assMap=new HashMap<>();
assMap.put("num",3);
//启动一个流程实例
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("hoildayPar", assMap);
System.out.println("流程实例ID:"+processInstance.getId());
}
}
package com.wn.Par;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
/*提交任务*/
public class CommitTask {
public static void main(String[] args) {
//获取ProcessEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//获取TaskService对象
TaskService taskService = processEngine.getTaskService();
//查询到自己的任务,然后通过任务ID进行提交
Task task = taskService.createTaskQuery().processDefinitionKey("hoildayPar").taskAssignee("zhangsan").singleResult();
//任务处理
taskService.complete(task.getId());
}
}
package com.wn.Par;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
/*提交任务*/
public class CommitTask {
public static void main(String[] args) {
//获取ProcessEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//获取TaskService对象
TaskService taskService = processEngine.getTaskService();
//查询到自己的任务,然后通过任务ID进行提交
Task task = taskService.createTaskQuery().processDefinitionKey("hoildayPar").taskAssignee("lisi").singleResult();
//任务处理
taskService.complete(task.getId());
}
}
package com.wn.Par;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
/*提交任务*/
public class CommitTask {
public static void main(String[] args) {
//获取ProcessEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//获取TaskService对象
TaskService taskService = processEngine.getTaskService();
//查询到自己的任务,然后通过任务ID进行提交
Task task = taskService.createTaskQuery().processDefinitionKey("hoildayPar").taskAssignee("zhaoliu").singleResult();
//任务处理
taskService.complete(task.getId());
}
}
当执行到并行网关时,说明当前流程实例有多个分支在运行;
并行任务不执行不分前后,有任务的负责人去执行即可;
当所有分支达到汇聚结点,并行网关就执行完成了;
package com.wn.Par;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
/*提交任务*/
public class CommitTask {
public static void main(String[] args) {
//获取ProcessEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//获取TaskService对象
TaskService taskService = processEngine.getTaskService();
//查询到自己的任务,然后通过任务ID进行提交
Task task = taskService.createTaskQuery().processDefinitionKey("hoildayPar").taskAssignee("sunqi").singleResult();
//任务处理
taskService.complete(task.getId());
}
}
package com.wn.Par;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
/*提交任务*/
public class CommitTask {
public static void main(String[] args) {
//获取ProcessEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//获取TaskService对象
TaskService taskService = processEngine.getTaskService();
//查询到自己的任务,然后通过任务ID进行提交
Task task = taskService.createTaskQuery().processDefinitionKey("hoildayPar").taskAssignee("zhouba").singleResult();
//任务处理
taskService.complete(task.getId());
}
}
执行完成后,整个流程就结束了;
原文:https://www.cnblogs.com/wnwn/p/12658727.html