4 Replies Latest reply on Jun 22, 2010 5:34 AM by Johannes Krämer

    How to recognize when async-node is finished?

    Johannes Krämer Newbie



      I'm trying to run a test with a simple process definition that contains the start state, an async node, a wait state and the end state. An example is attached.


      I create a process instance, remember the ID, obtain the root token and send a signal. The token then moves to the first node, which has set async to true. Then I save the processInstance and close the JbpmContext so the job message is sent to the job executor. The async node simply waits some time before it calls ExecutionContext.leaveNode() to send the token into a wait state.


      What I want to do now is: retrieve the process instance by the previously saved ID (with a newly created JbpmContext), get the root token and send a signal to make it take the transition to the end state.


      My problem is: How long do I have to wait after the token was sent to the async node if I want to be sure that the token has entered the next wait state and is no longer locked by the job? Is there any possibility to be notified?


      I tried to use a simple monitor where the main thread calls wait() after sending the first signal and the node implementation calls notifyAll() after leaveNode(), but the token is still locked by "Job(1)" when I send the second signal. It works if I wait some extra time (e. g. 250 ms) in the main thread before sending the second signal, but that is obviously not a good solution.


      Kind regards


      Johannes Krämer