cancel
Showing results for 
Search instead for 
Did you mean: 

multiInstance won't run task in parallel.

clstokes
Champ in-the-making
Champ in-the-making
I'm trying to execute a task on a collection in parallel, however no combination of settings seems to change the behavior from running sequentially.

Here's my test case in Groovy:
<blockcode>
package tests

import org.activiti.engine.ProcessEngine
import org.activiti.engine.ProcessEngineConfiguration
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.testng.annotations.BeforeClass
import org.testng.annotations.Test

class ParallelActivitiTests {

  @Test
  void test( ) {
    _logger.debug( "Starting…" )
    processEngine.getRuntimeService()
      .startProcessInstanceByKey( "ParallelServiceTest", [ values: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ] )
    _logger.debug( "Completed." )
    Thread.sleep( 30000l )
  }

  @BeforeClass
  void init( ) {
    ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
    configuration.setClassLoader( Thread.currentThread().getContextClassLoader() )

    processEngine = configuration
      .setJobExecutorActivate( true ) // allows asynchronous activities
      .buildProcessEngine()

    processEngine.getRepositoryService().createDeployment()
      .addClasspathResource( "activiti-processes/ParallelServiceTest.bpmn20.xml" )
      .deploy()
  }

  private ProcessEngine processEngine
  private static final Logger _logger = LoggerFactory.getLogger( ParallelActivitiTests.class )

}
</blockcode>

And ParallelServiceTest.bpmn20.xml:
<blockcode>
<?xml version="1.0" encoding="UTF-8" ?>
<definitions id="definitions"
             targetNamespace="http://activiti.org/bpmn20"
             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:activiti="http://activiti.org/bpmn">

  <process id="ParallelServiceTest">

    <startEvent id="start"/>
    <sequenceFlow id="_1" sourceRef="start" targetRef="logValue"/>

<!–
    <serviceTask id="logValue"
                 activiti:class="tasks.LogValueServiceTask"
                 activiti:exclusive="false">
      <multiInstanceLoopCharacteristics
          isSequential="false"
          activiti:collection="${values}"
          activiti:elementVariable="value">
      </multiInstanceLoopCharacteristics>
    </serviceTask>
–>

    <scriptTask id="logValue"
                name="Execute script"
                scriptFormat="groovy"
        >
      <multiInstanceLoopCharacteristics
          isSequential="false"
          activiti:collection="${values}"
          activiti:elementVariable="value">
      </multiInstanceLoopCharacteristics>
      <script>
        System.out.println(execution.getVariable("value"))
      </script>
    </scriptTask>

    <sequenceFlow id="_end" sourceRef="logValue" targetRef="end"/>
    <endEvent id="end"/>

  </process>

</definitions>
</blockcode>

Here's my test case output:
<blockcode>
Gradle test > com.weather.grid.services.platform.environment.ParallelActivitiTests.test STANDARD_OUT
    23:01:49.718 [Test worker] DEBUG c.w.g.s.p.e.ParallelActivitiTests - Starting…
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    23:01:50.391 [Test worker] DEBUG c.w.g.s.p.e.ParallelActivitiTests - Completed.
</blockcode>

I would expect values 0 to 9 to be possibly interleaved, not completely sequential. In my actual code, it's clear that my service task is called sequentially.

Note, neither the serviceTask or scriptTask work and marking both with
activiti:async="true" activiti:exclusive="false"
doesn't change their behavior.

What am I doing wrong?
18 REPLIES 18

trademak
Star Contributor
Star Contributor
Okay, so there's a restriction of 120 seconds on the thread execution and the multi-instance task can take 5+ minutes. And what you would like to see is that the multi-instance is performed in parallel with multiple threads so that it might only take 30 seconds or so?

Best regards,

trademak
Star Contributor
Star Contributor
Right, this is not supported currently in the job executor. But it could be an improvement for the next Activiti release to add support for multi threaded (managed by the application server) job executors.

Best regards,

trademak
Star Contributor
Star Contributor
Ok cool, looking forward to your findings.

isSequential is only meaningful when you use a user task or an other wait state task. For a service task you are right that there's no difference.

Best regards,

clstokes
Champ in-the-making
Champ in-the-making
The user guide should be updated to list this limitation (user task or an other wait state task) of multiInstanceLoopCharacteristics/isSequential. I wasted a lot of time on this.

trademak
Star Contributor
Star Contributor
Yes, the userguide could be improved there.

Best regards,

oliver35
Champ in-the-making
Champ in-the-making
Hi,

I have excatly the same requirement about having a real paralellism for multiinstance tasks execution  . (and also just as clstokes … lost some time trying to troubleshoot !!).

It would be nice to have this feature soon in Activiti.

My use case: I use activiti to to push configuration changes to  network devices. 

trademak
Star Contributor
Star Contributor
Ok, sorry to hear that you lost time on this. Yes it's a very valid feature. You can create a JIRA issue or upvote an existing issue. For our priority list we primarily look at the community demand, so if more people need this feature it will get a higher priority.

Best regards,

oliver35
Champ in-the-making
Champ in-the-making
Please could anyone (with a JIARA access) create an entry for this topic?

oliver35
Champ in-the-making
Champ in-the-making
ACT-2126 - multiinstance serviceTasks need real parallelism
has been created