4 Replies Latest reply on Sep 5, 2011 12:02 AM by garytse

    Using a Timer

    aminmc

      Hello

       

      Is it possible to get some clarification on the use of Timers in jBPM 5.  I would like to use a timer in my graph where after a given period of time the next node will be a service task call to do some work and complete the business process instance.  Is it true in order for the timer to work I need to reload the business process instance in memory and then call fireAllRules() on the statefulknowledgesession?  Someone mentioned to me that this is the case but it isn't refered in the documentation.  I presumed that there is a TimerService which registers which process has a Timer node and then invokes the necessary call to execute the Timer. 

       

      Any help would be appreciated,

       

       

      Cheers

        • 1. Re: Using a Timer
          amin-mc

          hello

           

          Would it be possible to get clarification this topic/discussion?

           

           

          Cheers

          • 2. Re: Using a Timer
            garytse

            >>>

            I would like to use a timer in my graph where after a given period of time the next node will be a service task call to do some work and complete the business process instance.

            <<<

            • That can easily be done.  The tricky part is that the current designer UI does not allow you to attach a timer event to an "Embedded Sub-Process" so you have to manually edit the XML for that.

             

            >>>

            Is it true in order for the timer to work I need to reload the business process instance in memory and then call fireAllRules() on the statefulknowledgesession? 

            <<<

            • No need.  The StatefulKnowledgeSession itself has a "timer thread" that kicks in when your schedule is due.

             

             

            http://sourceforge.net/projects/jbpm/files/jBPM%205/jbpm-5.1.0.Final/jbpm-5.1.0.Final-examples.zip/download

             

            I would highly recommend you to take a look at the examples.  jbpm-examples/src/main/resources/junit/BPMN2-TimerBoundaryEventCycle1.bpm2  is exactly the kind of thing you want.

             

            Good luck !

            • 3. Re: Using a Timer
              amin-mc

              Hi

               

              Thanks for your reply.  I will definitely take a look.  From what I can gather you need to have a statefulknowledgession open all the time?  I think there was a discussion before on what the best practice is for creating statefulknowledgesession.  Shoud there be a pool of statefulknowledgession or should you create a statefulknowledgesession everytime you interact with the process engine?

               

              Thanks

              • 4. Re: Using a Timer
                garytse

                Sorry but I guess it all depends on the processes.

                 

                For a pool/ multiple StatefulKnowledgeSession implementation :

                Say you have a long process that waits for external parties (eg human, webservice, etc).  When the event arrives, you need some way (eg DB) to look up and find out which process under which session should be informed of the event.

                 

                ie.  process id -> session id ->  interact with the correct StatefulKnowledgeSession object that contains your process object.

                 

                 

                For a single StatefulKnowledgeSession :

                You do not need that mapping, since all processes are under 1 single session.  However, I think there is a performance limitation in this implementation.  As far as I know, each session only have 1 thread to run all of the processes in a time-shared manner.  (Anyone can confirm ?)