cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to understand how service tasks and listeners work

neuquino
Champ in-the-making
Champ in-the-making
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!
1 REPLY 1

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

Is this how ServiceTask's Listeners works or are we missing something?
No, It should not work in this way. ServiceTask1 transaction is committed after the ServiceTask2  job is created. But I do not know what you missed.
(can you create jUnit test? http://forums.activiti.org/content/sticky-how-write-unit-test)

Regards
Martin