1 Reply Latest reply on Sep 17, 2011 1:26 PM by rrpeterson

    How to resume a persisted processInstance?


      Hey guys,


      I'm starting my ProcessInstance which consists of two service tasks seperated by a timer. 


      If I Thread.sleep() after creating my StatefulKnowledgeSession before calling ksession.dispose(), then the timer can complete and my 2nd task executes.


      If I call ksession.dispose() without sleeping, and re-load my ksession via JPAKnowledgeService.loadStatefulKnowledgeSession(w, x, y, z), my processInstance gets stuck on the timer even though more time has elapsed than it's limit.  Is there a method I need to call in order to get my processInstance to continue executing upon checking the timer status?


      Ideally I'd like to be able to create and start my processInstance, then close out the ksession.  Then periodically check on the status of the ksession to see if the timer's value has elapsed, and if so continue executing nodes.  I've tried calling ksession.startProcessInstance() on the loaded session and giving it the persisted processId, but I get the exception msg: "A process instance can only be started once"  It almost seems like I need to call something like ksession.resume(), but no such method exists (to my knowledge)


      Thanks for any suggestions/help!

        • 1. Re: How to resume a persisted processInstance?

          A partial answer I've found after playing with timers:


          The time defined by the timer must pass within the method that invokes or retrieves the session in order to fire the next node. 


          In other words, a string of nodes with a timer (for instance 15 seconds) all nodes will execute up to the timer and then will return, persisting the ksession.  If a Thread.sleep() for more than 15 seconds happens before calling session.dispose() in the original session.startProcess(), then the timer completes and the next nodes in the process instance will fire.


          Also the same behavior happens retrieving the session via JPAKnowledgeService.loadStatefulKnowledgeSession, if a Thread.sleep() for a length over the timer value happens, then the timer expires and the next node is called.



          Is there a way to setup a timer, for instance 2 hours, that when the ksession is retrived will check the time between the creation of the timer node, and current time?  Otherwise I don't see how timers would be useful, unless you're willing to dedicate a thread to each processInstance to sit & poll at fixed intervals to check if timers have expired?