AnsweredAssumed Answered

Trying to understand how service tasks and listeners work

Question asked by neuquino on Apr 16, 2015
Latest reply on Apr 17, 2015 by martin.grofcik
We are having a problem and we'd like to understand a bit how Activiti's Engine works. Let assume the following flow example:

start -> ServiceTask1 -> ServiceTask2 -> end

  • Both ServiceTasks are async
  • Both ServiceTasks has a Listener when each of them starts.
  • Both Listeners update a row in one of our business tables.


The problem is that we are having Optimistic Lock errors because it seems that both listeners are trying to update the same row at the same time.

We guess that what is happening is:
  • The ServiceTask doesn't wait for the start Listener to finish
  • So ServiceTask1 finishes before its start Listener finishes and the start Listener of ServiceTask2 reads the db row before the Listener of ServiceTask1 writes the update
  • ServiceTask1's Listener writes the update
  • When ServiceTask2's Listener wants to write the update, the version is different so it throws an optimistic lock.


So, the questions we need to answer are:

  • Is this how ServiceTask's Listeners works or are we missing something?
  • Is there any way to make ServiceTasks to wait for the start Listener?
Thanks in advance!

Outcomes