Hi,
From Parent process I am triggering multiple child processes using callActivity.
Each child process sets a variable called “serviceKey” with a String value.
Now how can I get a variable in Parent process called “serviceKeyList” with List<String> as the value?
After callActivity parallel child processes are all done, using asyncAfter and End Execution Listener I can trigger an execution listener in the Parent process.
Is there any Java code example where I can iterate over all child processes variables in this execution listener and make a list of String? Also, is there a better approach within Camunda itself for such an aggregation (Out mapping propagation would not work because one child process would override another child process variable instead of aggregating).
Have the child process return it’s serviceKey as a local out mapping. This creates a local in the instance of the multi-instance parallel call task of the parent. Add an “end” execution listener to each instance of the parent multi-instance which reads the (global) serviceKeyList, appends the local serviceKey to it and finally updates the serviceKeyList variable.
For clarity in the process engine logs, I’ve also passed down the loopCounter to the child process so that it can do a simple sys.out log of that value. This helps a bit when comparing behaviour with/without “async before” and “exclusive” flags.
If you configure the parallel multi-instance with async before & exclusive == false you will get some contention (optimistic locking exception) on writes of the serviceKeyList variable but the engine will keep trying these until resolved (and they will resolve) …
Hi, The use of the local out mapping variable in callActivity is useful for me in this situation. Thanks.
I did not understand the point about locking issue. When I enable asyncBefore then exclusive is also enabled by default by Camunda modeler and I keep it that way. So I assume that locking issue will not happen in this case?
Hey @firstpostcommenter - yes, you can leave “exclusive” on and you won’t get the OLE. On the other hand you won’t get parallel execution of the child process across the process engine job workers because:
An exclusive job cannot be performed at the same time as another exclusive job from the same process instance.
Yes, the end execution listener will be called per child process irrespective of async
oh, I was not aware that parallel multi-instance will behave like a sequential multi-instance when exclusive flag is set to true. Should exclusive flag be set to false in both the “Called element” section and “Multi-instance” section of the callActivity for it to behave as parallel multi-instance?
I see that even with asyncBefore and Exclusive flag enabled, multiple child processes are being triggered from the Parent process. Might be because the all delegates and the child process are also having asynchronous continuation. So only the triggering of child process from callActivity might be happening sequentially but both child process are running in parallel.