AnsweredAssumed Answered

Implementing asynchronous service task. need help

Question asked by imoraru on Jan 6, 2012
Latest reply on Jan 6, 2012 by imoraru
Hi,

I am trying to implement a process where two asynchronous tasks run in parallel.
The process layout looks like this:
[attachment=0]parallel-process.tiff[/attachment]
If the activiti:async is not set, all the tasks are executed sequentially.
If I set the activiti:async=true for the parallel tasks, the first task executes but the code for the parallel tasks is never called.
I feel I am missing something trivial here. I looked thru the tutorial and the examples but I can't figure it out.
I am new to this (just started couple of days ago) so have mercy if the answer is too obvious  :) .

The code I used to run the process is a slight modification from the 10 min. tutorial:
public static void main(String[] args) {
   
    // Create Activiti process engine
    ProcessEngine processEngine = ProcessEngineConfiguration
      .createStandaloneProcessEngineConfiguration()
      .buildProcessEngine();
   
    // Get Activiti services
    RepositoryService repositoryService = processEngine.getRepositoryService();
    RuntimeService runtimeService = processEngine.getRuntimeService();
   
    // Deploy the process definition
    DeploymentBuilder dep = repositoryService.createDeployment();
      dep.addClasspathResource("process-1.bpmn20.xml");
      dep.deploy();
   
    // Start a process instance
    String procId = runtimeService.startProcessInstanceByKey("Process-1").getId();
   
…..
The process definition is as follows:
<?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: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="Process-1" name="process-1">
    <documentation>Place documentation for the 'process-1' process here.</documentation>
    <startEvent id="startevent1" name="Start"></startEvent>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
    <parallelGateway id="parallelgateway1" name="Parallel Gateway"></parallelGateway>
    <sequenceFlow id="flow3" name="" sourceRef="parallelgateway1" targetRef="servicetask3"></sequenceFlow>
    <sequenceFlow id="flow4" name="" sourceRef="parallelgateway1" targetRef="servicetask2"></sequenceFlow>
    <sequenceFlow id="flow5" name="" sourceRef="servicetask1" targetRef="parallelgateway1"></sequenceFlow>
    <inclusiveGateway id="inclusivegateway1" name="Inclusive Gateway"></inclusiveGateway>
    <sequenceFlow id="flow6" name="" sourceRef="servicetask3" targetRef="inclusivegateway1"></sequenceFlow>
    <sequenceFlow id="flow7" name="" sourceRef="servicetask2" targetRef="inclusivegateway1"></sequenceFlow>
    <endEvent id="endevent2" name="End"></endEvent>
    <sequenceFlow id="flow8" name="" sourceRef="inclusivegateway1" targetRef="endevent2"></sequenceFlow>
    <serviceTask id="servicetask1" name="Task 1" activiti:class="com.tieroneoss.tnp.workflow.TnpServiceTask"></serviceTask>
    <serviceTask id="servicetask2" name="Parallel Task 2" activiti:async="true" activiti:class="com.tieroneoss.tnp.workflow.TnpService3"></serviceTask>
    <serviceTask id="servicetask3" name="Parallel Task 1" activiti:async="true" activiti:class="com.tieroneoss.tnp.workflow.TnpService5"></serviceTask>
  </process>
</definitions>

So I have two questions:
1. What am I missing?
2. I assume that at some point in the execute() method of the java class implementing the service I have to call something like task.complete(). How do I get the instance of the task that is executing?

Looking forward for your input.
TIA.
Ion

Outcomes