cancel
Showing results for 
Search instead for 
Did you mean: 

How to multi instance on sub process

nbuso
Champ in-the-making
Champ in-the-making
Hi,

I'm trying to obtain concurrent execution of a subprocess, but the behaviour is not what expected; this is how the subprocess is defined:

    <subProcess id="PerDomainSubProcess" name="PerDomainSubProcess" activiti:async="true">
      <multiInstanceLoopCharacteristics isSequential="false" activiti:collection="domainIds.list" activiti:elementVariable="domainId"></multiInstanceLoopCharacteristics>
      <startEvent …..

I was thinking the subprocesses would be started for any element of the collection in parallel (concurrently), but it's not happening, the subprocesses created are executed sequentially.

Am I missing something? Can somebody point me on how to achieve this behaviour?

n.

P.S.: I was trying to follow the suggestions I found in this post http://forums.activiti.org/en/viewtopic.php?f=8&t=4746&p=18607&hilit=concurrent+subprocess#p18607

——————

I created a simple process: it accept in input a list of values separated by comma (a,b,c,d) and in a subprocess it print 100000 line per element of the list. The print is done by a groovy script.

If I execute the process I can notice in the log that the rows are all printed in sequence. The subprocess is async and multi instance on the list of inputs.
I did something wrong? isn't possible to obtain concurrency?
Do I need to raise a JIRA ticket?

Somebody can give me some hints on this?


I paste here the process, because the forum upload seam not to work.


<?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="process1" name="process1">
    <startEvent id="startevent1" name="Start" activiti:initiator="initiator"></startEvent>
    <userTask id="usertask1" name="Data Inputs" activiti:assignee="${initiator}">
      <extensionElements>
        <activiti:formProperty id="ids"></activiti:formProperty>
      </extensionElements>
    </userTask>
    <scriptTask id="scripttask1" name="variableList" scriptFormat="groovy">
      <script><![CDATA[def ids = execution.getVariable("ids");
def idsList = ids.tokenize(",");
execution.setVariable("ids.list", idsList);]]></script>
    </scriptTask>
    <subProcess id="subprocess1" name="Sub Process" activiti:async="true">
      <multiInstanceLoopCharacteristics isSequential="false" activiti:collection="ids.list" activiti:elementVariable="identifier"></multiInstanceLoopCharacteristics>
      <startEvent id="startevent2" name="Start"></startEvent>
      <scriptTask id="scripttask2" name="simple printout" scriptFormat="groovy">
        <script><![CDATA[for (idxVar in 0..100000) {
println(execution.getVariable("identifier")+"_"+idxVar);
}]]></script>
      </scriptTask>
      <endEvent id="endevent1" name="End"></endEvent>
      <sequenceFlow id="flow4" name="" sourceRef="startevent2" targetRef="scripttask2"></sequenceFlow>
      <sequenceFlow id="flow5" name="" sourceRef="scripttask2" targetRef="endevent1"></sequenceFlow>
    </subProcess>
    <endEvent id="endevent2" name="End"></endEvent>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="usertask1" targetRef="scripttask1"></sequenceFlow>
    <sequenceFlow id="flow3" name="" sourceRef="scripttask1" targetRef="subprocess1"></sequenceFlow>
    <sequenceFlow id="flow6" name="" sourceRef="subprocess1" targetRef="endevent2"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_process1">
    <bpmndi:BPMNPlane bpmnElement="process1" id="BPMNPlane_process1">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35" width="35" x="90" y="150"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55" width="105" x="170" y="140"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="scripttask1" id="BPMNShape_scripttask1">
        <omgdc:Bounds height="55" width="105" x="330" y="140"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="subprocess1" id="BPMNShape_subprocess1" isExpanded="true">
        <omgdc:Bounds height="205" width="381" x="510" y="65"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="startevent2" id="BPMNShape_startevent2">
        <omgdc:Bounds height="35" width="35" x="550" y="152"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="scripttask2" id="BPMNShape_scripttask2">
        <omgdc:Bounds height="55" width="105" x="630" y="142"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35" width="35" x="790" y="152"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="585" y="169"></omgdi:waypoint>
        <omgdi:waypoint x="630" y="169"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="735" y="169"></omgdi:waypoint>
        <omgdi:waypoint x="790" y="169"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
        <omgdc:Bounds height="35" width="35" x="940" y="150"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="125" y="167"></omgdi:waypoint>
        <omgdi:waypoint x="170" y="167"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="275" y="167"></omgdi:waypoint>
        <omgdi:waypoint x="330" y="167"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="435" y="167"></omgdi:waypoint>
        <omgdi:waypoint x="510" y="167"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="891" y="167"></omgdi:waypoint>
        <omgdi:waypoint x="940" y="167"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
3 REPLIES 3

jbarrez
Star Contributor
Star Contributor
First of all, did you read http://activiti.org/faq.html#WhatIsTheDifferenceBetweenProcessConcurrencyAndJavaConcurrency ?

So yes, your subprocesses will be executed sequentially in the engine.
However, the difference with 'isSequential='true'' is that now all your subprocesses are created at once. In the 'true' case, one subprocess will be created, and when that is finished, the second one will be created.

nbuso
Champ in-the-making
Champ in-the-making
thank for the reply.

first of all I'm new to BPM, I'm learning! Than sorry if I'm not completely aware of the subject.

First of all, did you read http://activiti.org/faq.html#WhatIsTheDifferenceBetweenProcessConcurrencyAndJavaConcurrency ?
Yes I read the FAQ before to write the process; but it seem a bit outdated or I didn't read correctly?
It's written "In the future we envision configurations that allow for asynchronous execution of the service methods", what you mean with service methods? are you speaking about tasks in some way?
it's also written " Asynchronous continuations will be introduced to allow for a more fine grained demarcation of transactions for those situations where it is needed"

The User Guide document about this http://activiti.org/userguide/index.html#asyncContinuations. For this reason I'm thinking Activiti is a step forward the FAQ.

So yes, your subprocesses will be executed sequentially in the engine.
However, the difference with 'isSequential='true'' is that now all your subprocesses are created at once. In the 'true' case, one subprocess will be created, and when that is finished, the second one will be created.

Changing a bit the process I obtained something different; I changed the configuration of the first task in the subprocess:

      <scriptTask id="scripttask2" name="simple printout" activiti:async="true" activiti:exclusive="false" scriptFormat="groovy"> …

In this way I'm obtaining some kind of concurrency, is this a correct way to obtain concurrency? but seem to be limited in number of thread used (3). Can this value be changed?
I'm obtaining also some exceptions:


org.activiti.engine.ActivitiOptimisticLockingException: ExecutionEntity[7713] was updated by another transaction concurrently

Explained here http://forums.activiti.org/en/viewtopic.php?f=6&t=4124&p=16187&hilit=ActivitiOptimisticLockingExcept...

Do you think I can resolve this with the suggestions proposed by ' frederikheremans'?

I will continue reading forums, to me seem other people are interested in concurrency and the User Guide seem not extensively clear on this. I think you should point the reader to "the BPMN" way to manage concurrency, also using external references.


n.

jbarrez
Star Contributor
Star Contributor
In this way I'm obtaining some kind of concurrency, is this a correct way to obtain concurrency? but seem to be limited in number of thread used (3). Can this value be changed?

Yes. In some way. Async continuations are also a way of 'designing' your processes.

You must ask yourself before introducing it: do I really need threading? In most cases, we see that people don't really need threading added to their business processes, and having 'business concurrency' is often way more appropriate (that was actually the section I linked to in the FAQ).

I'm obtaining also some exceptions:

Yes, these are expected when you introduce concurrency.