user2894296
user2894296

Reputation: 630

Cancel a user task when another user task is completed

Two user tasks (task A and B) are created in parallel, and when one task is completed need to cancel the other vice versa. This can be done with the use of a task listener (event on complete). However the issue is if both tasks are completed at the same time how to handle it?

Upvotes: 0

Views: 585

Answers (2)

Destiny.Wang
Destiny.Wang

Reputation: 169

I recommend that you create a userTask with multiple instances. It can create multiple usertasks at the same time and set different conditions to end the multiple instances.

here is the syntax rules
<userTask id="userTask1" name="Activiti is awesome!" activiti:assignee="${user}">
    <multiInstanceLoopCharacteristics isSequential="false" activiti:collection="${userList}" activiti:elementVariable="user">
        <completionCondition>${nrOfCompletedInstances == nrOfInstances}</completionCondition>
    </multiInstanceLoopCharacteristics>
</userTask>
  • IsSequential means parallel or serial creation
  • ${userList} means a list object received from the outside
  • completionCondition means that all outstanding userTask will be automatically deleted once the conditions you set are met.

More information can be found at activiti User Guide#Multi-instance

Hope that can solve your problem!

Upvotes: 0

salaboy
salaboy

Reputation: 4143

Have you tried that out? Competing a task is a transactional operation, that means that if both tasks are completed at the same time only one transaction will “win” and the other will be rolled-back pushing the second transaction to be retried. In general that should work if you have that retrying mechanism

Upvotes: 2

Related Questions