RuntimeService.startProcessInstanceByKey becomes non-blocking when running process with async service task

I have simple camunda process definition that I’m running from the code

ProcessInstance startProcessInstanceById = runtimeService.startProcessInstanceByKey(processName);

I noticed that is I’m not marking any async before\after checkboxes, method startProcessInstanceByKey completes when actual process definition is completed, however I would like my service tasks to run concurrently so I’m marking them as async
Now when running method startProcessInstanceByKey it finishes immediately and whole process is continues.
I want to be able to wait until whole process will finish and then continue with my code execution. How can I achieve that behavior?

Thanks

Hi Evgeny,

I think this might be interesting for you:

I didn’t understand what is your goal.

Best regards,
Yana

Hello Yana,
Thanks for the answer
My goal is to run process above from my java code and wait until it completes however now method startProcessInstanceByKey returns immediately and I don’t know when process actually completes.

If I understand correct, there is no true concurrency when using parallel gateway? My ServiceTask can take a while (up to 20 minutes) so I would like to run both tasks in parallel. Is this any solution for this case?

Thanks

@Evgeny_Makarov Are you able to get a solution for this? Even i am in the need for the answer for your question now.

If you want to continue the execution of your “main” program only after the process is complete, and the process has an async point, the you have to implement busy waiting in the main program. I.e. you should have a loop and periodically check the state of the process. You get the process id as the result of the start call. This is how camunda engine works. Synchronous execution only takes place until the first job in the process is finished.

Thanks @fml2 is there any example code for this in git? What I understand is I have to keep polling in my application thread to check the process instance is completed or not? I am using Spring boot camunda , how will i check that? any method that provides this in runtimeservice?

You’ll probably have to use the history service and query for the process instance with the id you got when you started the process. When the property isEnded (I’m not sure the name is correct) becomes true it means that the process is completed.