AnsweredAssumed Answered

Custom Multi-instance Service Task

Question asked by jcoveron on Aug 5, 2017


Activiti version: 6.0


I am creating a Service Task that extends TaskActivityBehavior class. This is because I need to do a long running job outside Activiti. This works fine.


The doubt I have is when configuring this Service Task as a sequential multi instance task. I see that Activiti enters class MultiInstanceActivityBehavior prior to entering my service task, but my service task is only executed once.


I also saw that the variables nrOfInstances, nrOfActiveInstances, nrOfCompletedInstances and loopCounter are correctly set. But still, the execute method of my service task is only executed once.


Here is the code of the execute method.



public void execute(DelegateExecution execution) {
   try {
      FileHandler fh = new FileHandler("name", "filename", new FolderHandler());
      execution.setVariable(fh.getName(), fh);

      GenericTaskEntity task = new GenericTaskEntity();
      task.setPriority((int) counter.incrementAndGet());
   } catch (Exception e) {
         "There was a problem when trying to execute task '" + BehaviorTaskType.TASK1.toString() + "' "



And here is the trigger method:



public void trigger(DelegateExecution execution, String signalName, Object signalData) {



And finally, this is how the XML part for the service task looks like:



<serviceTask id="servicetask1" name="Service Task" activiti:delegateExpression="${task1}">
   <multiInstanceLoopCharacteristics isSequential="true">



Many thanks in advance for your help.