cancel
Showing results for 
Search instead for 
Did you mean: 

Instant insert/update of variable inside JavaDelegate execution?

nvulchev1
Champ in-the-making
Champ in-the-making
We have use-case in which we perform some relatively long-running operations (think of up-to 30 sec to 1 minute) as part of a JavaDelegate.execute(). We have the requirement to report the progress of the execution of the JavaDelegate, which we currently do as updates of variables inside DelegateExecution. These variables are simultaneously read within a REST call of our backend via RuntimeService.getVariable(). Still we observe that the variables we set in the JavaDelegate implementation are committed to the database (and their up-to-date values are visible via RuntimeService.getVarialbe() call in our web request-handling thread) only after a successful finish of the execute() method.
What we want to achieve is direct insert/update of the variables in the database during the JavaDelegate.execute() method execution.   One workaround that we find to make this happen was to set the progress variables via RuntimeService.setVariable() call in a new Thread, which is not very clean. So, is there any recommended/more elegant way to achieve our goal?

Thanks,
Nikolay
2 REPLIES 2

jbarrez
Star Contributor
Star Contributor
That is the way Activiti works: during the execution of your delegate a db transaction is kept open and it is committed at the end. There is no clean way to get what you want with Activiti, except storing it in a Threadlocal on the service task or a table outside of Activiti.

nvulchev1
Champ in-the-making
Champ in-the-making
Thanks, we also took the external table approach as we don't want to mess with Acitiviti internals.