Activiti7工作流引擎:高阶篇 ReceiveTask
Posted vbirdbest
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Activiti7工作流引擎:高阶篇 ReceiveTask相关的知识,希望对你有一定的参考价值。
ReceiveTask 称之为接收任务、等待任务等。当执行流进入ReceiveTask时会先执行执行监听器,然后整个执行流进入wait等待状态,而且在act_ru_task中不没有当前正在进行中的任务,当执行流执行trigger()方法时才会触发正在睡眠的ReceiveTask,进入下一个节点。
<process id="ReceiveTaskProcess" isClosed="false" isExecutable="true" processType="None">
<startEvent id="start" name="StartEvent"/>
<receiveTask activiti:exclusive="true" id="receiveTask" name="ReceiveTask">
<extensionElements>
<activiti:executionListener event="start"/>
<activiti:executionListener class="com.example.activiti7.ReceiveTaskDelegate" event="start"/>
<activiti:executionListener class="com.example.activiti7.ReceiveTaskDelegate" event="start"/>
</extensionElements>
</receiveTask>
<endEvent id="end" name="EndEvent"/>
<userTask activiti:exclusive="true" id="userTask1" name="UserTask1"/>
<userTask activiti:exclusive="true" id="userTask2" name="UserTask2"/>
</process>
public class ReceiveTaskDelegate implements ExecutionListener
@Override
public void notify(DelegateExecution execution)
Map<String, Object> variables = execution.getVariables();
System.out.println(execution.getEventName() + "-" + execution.getCurrentFlowElement().getId());
一:启动任务
@Test
void testStartProcess()
runtimeService.startProcessInstanceByKey("ReceiveTaskProcess");
启动流程实例,UserTask1进入当前任务。
二:完成UserTask
@Test
void testCompleteUserTask1()
Task currentTask = taskService.createTaskQuery().processDefinitionKey("ReceiveTaskProcess").singleResult();
taskService.setAssignee(currentTask.getId(), "zhangsan");
taskService.complete(currentTask.getId());
当UserTask1完成后进入ReceiveTask,执行了ReceiveTask对应的代理ReceiveTaskDelegate,
act_ru_task中竟然没有数据,而act_ru_exectuion中当然活动竟然是receiveTask。
三:trigger
@Test
void testTriggeReceiveTask()
Execution execution = runtimeService.createExecutionQuery()
.processDefinitionKey("ReceiveTaskProcess")
.activityId("receiveTask")
.singleResult();
runtimeService.trigger(execution.getId());
ReceiveTask就像多线程中的wait(), 而trigger()就像多线程中的notify()了。
以上是关于Activiti7工作流引擎:高阶篇 ReceiveTask的主要内容,如果未能解决你的问题,请参考以下文章
Activiti7工作流引擎:高阶篇 ProcessDefinitionUtil