cancel
Showing results for 
Search instead for 
Did you mean: 

Question on the startProcessInstanceByKey

sathish1
Champ in-the-making
Champ in-the-making
There is a process Instance which is running, for sake of discussion I call this process instance as "A" and within this I have to get Process Instance running "B" in a separate thread. So what I did was once I started the process A, in one of the service task of Process A, am coding to something like this

execution.getEngineServices().getRuntimeService().startProcessInstanceByKey("PROCESSB", processSaveVariables);


I was thinking the strateProcessInstanceByKey was going to start a new thread and will not run in Process A thread., But when I print the thread name for Process A and Process B, I get same thread name.

Can you please advise why is that a new thread is not getting kicked off when I call the startProcessInstanceByKey within Process A to start Process B??

Thanks in advance.
3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
All API-calls are synchronous, executed by the calling thread. All calls to the API you do from within a JavaDelegate (or any other listener that is called as part of the process) are run in the same transaction AND thread. This is by design, to make sure process state is consistent between wait-states.

If you want to have the second process started in another thread, make the first activity in process B asynchronous. The process B will be started synchronously in process A's transaction, but won't run the actual activity - rather, it's added as a job and executed in another thread and this will continue running process B, independent of process A's state/execution.

A better way might be to use a call-activity, instead of starting the process B using the runtimeService. Marking this call activity as async=true will have the subprocess be executed in a separate thread (by the job-executor). This will make process B an integral part of process A and can be used to wait on the completion of process B, executing other stuff in process A (eg. using parallel gateway in A)

Got it. Moved the start process to Call-activity. Really appreciate the time with your explanation.

frederikherema1
Star Contributor
Star Contributor
No worries, glad to help Smiley Wink