cancel
Showing results for 
Search instead for 
Did you mean: 

Doubt about the execution of a multi instance task

ebbinvarghese
Champ in-the-making
Champ in-the-making
Hi,

The activiti version is 5.18
My application is in PHP and I use activiti-rest.

I have the following multi instance task in a process.

<userTask id="panel_member_evaluation_1" name="Panel  Member Evaluation" activiti:assignee="${assignee}">
      <documentation>Task denoting the evaluation performed by the panel members</documentation>
      <extensionElements>
        <activiti:executionListener event="start" expression="${partnerAssessment.setWorkflowStatus(execution, 3, 'General Assessment In Progress')}"></activiti:executionListener>
        <activiti:taskListener event="create" expression="${partnerAssessment.setPanelMemberWorklist(task , 1)}"></activiti:taskListener>
      </extensionElements>
      <multiInstanceLoopCharacteristics isSequential="false" activiti:collection="${partnerAssessment.assignPanelMembers(execution, 1)}"                                               activiti:elementVariable="assignee">
        <completionCondition>${nrOfCompletedInstances/nrOfInstances == 1 }</completionCondition>
      </multiInstanceLoopCharacteristics>
</userTask>

I use the activiti:collection attribute to invoke the method assignPanelMembers( ) which will fetch the list of assignees from the PHP application via a REST call.

Some additional operations are carried out by using the task and execution listeners.

I understand that for a multi instance task the execution listener on start will be called n + 1 times where n is no of users in the collection.
In my trial this was 1, so the listener was executed 2 times.

However I observed that the method assignPanelMembers( ) of the activiti:collection is getting called 3 times.
Is this normal ? I expected it to be executed only once during the creation of the multi instance task.
I had written some data initialization code along with the code to fetch the assignee list inside the assignPanelMembers( ) which is now executing multiple times.

Is there a way to invoke a method of a bean which will be invoked only once for this multi instance task ?
If there is , then is it possible to pass the execution inside it's expression like in an execution/task listener ?

Thanks in advance.
Ebbin



3 REPLIES 3

ebbinvarghese
Champ in-the-making
Champ in-the-making
Sorry. The definition of the task got removed.

Here it is.

<userTask id="panel_member_evaluation_1" name="Panel  Member Evaluation" activiti:assignee="${assignee}">
      <documentation>Task denoting the evaluation performed by the panel members</documentation>
      <extensionElements>
        <activiti:executionListener event="start" expression="${partnerAssessment.setWorkflowStatus(execution, 3, 'General Assessment In Progress')}"></activiti:executionListener>
        <activiti:taskListener event="create" expression="${partnerAssessment.setPanelMemberWorklist(task , 1)}"></activiti:taskListener>
      </extensionElements>
      <multiInstanceLoopCharacteristics isSequential="false" activiti:collection="${partnerAssessment.assignPanelMembers(1, gms_partner_id, assessment_id, 1)}" activiti:elementVariable="assignee">
        <completionCondition>${nrOfCompletedInstances/nrOfInstances == 1 }</completionCondition>
      </multiInstanceLoopCharacteristics>
    </userTask>

jbarrez
Star Contributor
Star Contributor
it could very well be the expression is called multiple times: the first time to determine the total, next times to determinate the elementVariable. Why would that be a problem? Is calling that bean multiple times harmful?

ebbinvarghese
Champ in-the-making
Champ in-the-making
This bean calls a REST service on my PHP application which will fetch the assignees from my application database and return it to the activiti: collection of the multi instance task.

This bean also calls a service that performs some updates on my application database.
I would like these to be executed only once for this multi instance task no matter how many instances are to be created.
Is this possible ?
I found that this is not possible if I place it under the execution listener or task listener of this task.
I thought that by placing it under the activiti:collection attribute it would be executed only once.
Is there another way to ensure that this code will be called only once ?

Also when the activiti:collection bean gets executed multiple times, wont there be multiple database fetches ( via my REST call ) ?