1 Reply Latest reply on Aug 20, 2012 12:34 PM by m_arnold123

    BPMN Timers - threads and persistence


      I have a problem using BPMN2 Timers with jBPM 5.3.  I can't see how to resolve my problem, so looking for help from the community...


      I have read: jBPM5 timers and persistence https://community.jboss.org/thread/164992 and the bug https://issues.jboss.org/browse/JBPM-3170 , which closed as not a bug, but doesn't seem to provide or refer to a full solution.


      I am using jBPM5 deployed in a 4 node JBoss AS 5.1 cluster, used from an EJB 3 application.  We handle about 100K new process instances per day, bursting at 20 per second.  We want to use BPMN2 Timers to make our processes wait for durations from a couple of seconds to a couple of months.


      1.  If I have a 1 million process instances waiting for timers, jBPM surely won't create 1 million threads all sleeping until their timeout? This is obviously not scalable.


      2. Does jBPM ever create, join or synchronise threads?  As we are using jBPM in an application server, I am worried about it performing its own thread management.


      3. Until now, we have been disposing and reloading StatefulKnowledgeSession as our processes execute.  I understand this will prevent the timers from firing.  Instead I should never dispose sessions and reload sessions when the application server starts?  How do I know which sessions may be waiting for timers in order to know which to reload?


      4. Do events (for BPMN2 receive and catch) also require the session to not be disposed in the same way as timers?


      Thanks for any help.  Basically I'm trying to get jBPM to work well with JBoss in a scalable way...

        • 1. Re: BPMN Timers - threads and persistence

          I had a dig into jBPM source code, and found org.drools.time.impl.JDKTimerService.  It looks to me like jBPM5 uses the Java SE 6

          ExecutorService (http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html). 


          It would be an *extremely* useful enhancement if jBPM5 could be configured to use the Java EE TimerService.  (http://docs.oracle.com/javaee/5/tutorial/doc/bnboy.html).  I think using the ExecutorService will be fraught with problems in an HA + EJB3 environment.  If I can't find a solution I will have to create a custom workitemhandler just to allow processes to sleep for a configurable period of time (using the Timer Service) - but this obviously won't use the proper BPMN2 syntax.


          I am left with the problem of how & when to dispose sessions, and how to load sessions from persistence when the cluster starts.  I thought I might try to use SFSBs to maintain the knowledge sessions while the cluster is up, and will use a @Startup @Singleton to load the knowledge sessions from persistence which may have timers.  Has anyone had any luck doing anything similar?


          I run each process in its own StatefulKnowledgeSession. If I call "pi = ksession.startProcessInstance(pi.getId());" can I use the pi.getState() to determine whether I can safely dispose the StatefulKnowledgeSession after the call?  ie. if getState == STATE_ABORTED || STATE_COMPLETED?  Any advice on how I can determine when a StatefulKnowledgeSession has no timers and therefore can be disposed?


          This problems seem like they must be very common... hopefully someone has some advice!?