Hello,
I’m starting process instance using JavaAPI, I would like to then wait until process is completed (or, even preferably, reaches some state) and after that execute some more code, like that:
ProcessInstance instance = engine.getRuntimeService().startProcessInstanceByKey("my-process", variables);
//do something after process instance has finished
@mpawlowski if your whole process is executed in synchronous passion(without wait states), it’s possible to wait till completion of the process. Refer the below model for sync execution:
If your process is executed in asynchronous passion(also contains wait states), it’s not possible to wait till completion of the process. So at that time you will wait in the current wait state of process. By default all user task types will have wait state. In this scenario, you can’t wait until the process completes. Refer the below model for async execution:
As an additional bit of advice, you can also have an end listen on the process itself - so that if you have multiple end events or ways in which the process will end it will always trigger. You can see that in the properties panel when you select the canvas.
Of course you can wait! Just implement a busy waiting, i.e. wait for a period of time (sleep), then check the process state, then wait again if it’s not completed. It’s not very cool but it works well. Be sure to implement some timeout logics.