cancel
Showing results for 
Search instead for 
Did you mean: 

ProcessInstance only returned after task ended

kkdw
Champ in-the-making
Champ in-the-making
Hello,
I am trying to use Activiti as a sort of "pimped up" state machine -> the Process only contains ServiceTasks which point towards Java Delegates. In order to monitor the state of a running process I would like to access the processInstance Object after it is started. However when starting my process via

ProcessInstance procInst = runtime.startProcessInstanceByKey("myProcess");


procInst is only returned after the process ended. I activated the Async Executor via:
ProcessEngineConfiguration config = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
config.setAsyncExecutorEnabled(true);
config.setAsyncExecutorActivate(true);


And set the first service task in the Diagram to asynchronous, still no luck

My question is, if this is due to the process only containing Service Tasks (I read that startProcessInstanceByKey() is blocking and it will return only when process engine has nothing more to do (for instance, it reached user task which requires user interaction)), if so is there a workaround ?

Or should this actually work, i.e. I am doing something wrong?

Thanks in advance,
Konrad
2 REPLIES 2

jbarrez
Star Contributor
Star Contributor
No, when your service task is async, the method call returns before the service task is executed.

Note that the ProcessInstance object is a stale object, it wont be updated with the latest values, unless you refetch it.

kkdw
Champ in-the-making
Champ in-the-making
Hi!
Thanks a lot for your answer. I had indeed a bug in my code - now making the first service task asynchronous - will return the ProcessInstance object back.
Cheers,
Konrad