Discussion:
[jboss-user] [jBPM] - Multiple Sessions - Timer Tasks - some triggered twice and some missed
tmag
2013-01-15 16:53:26 UTC
Permalink
tmag [https://community.jboss.org/people/tmag] created the discussion

"Multiple Sessions - Timer Tasks - some triggered twice and some missed"

To view the discussion, visit: https://community.jboss.org/message/792064#792064

--------------------------------------------------------------
Our bpmn process has a set of timer tasks.
* When we use a single session to create all processes & reload that single session - all timer tasks resuming for different processes without any issue.
* When we use multiple sessions (we tried with 2 sessions)  to create processes & reload all those sessions to restore timers - some timer tasks triggering twice & some not triggered at all.
Anyone faced this issue with timer tasks on multiple sessions?

We are using 5.4.Final.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/792064#792064]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
doboss
2013-01-15 22:05:43 UTC
Permalink
doboss [https://community.jboss.org/people/doboss] created the discussion

"Re: Multiple Sessions - Timer Tasks - some triggered twice and some missed"

To view the discussion, visit: https://community.jboss.org/message/792129#792129

--------------------------------------------------------------
Shot in the dark, but are you disposing of your sessions after you use them?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/792129#792129]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
tmag
2013-01-16 15:49:56 UTC
Permalink
tmag [https://community.jboss.org/people/tmag] created the discussion

"Re: Multiple Sessions - Timer Tasks - some triggered twice and some missed"

To view the discussion, visit: https://community.jboss.org/message/792384#792384

--------------------------------------------------------------
We are not disposing the sessions - as we need them to restore timer tasks on server reboot.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/792384#792384]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
tmag
2013-01-18 15:36:40 UTC
Permalink
tmag [https://community.jboss.org/people/tmag] created the discussion

"Re: Multiple Sessions - Timer Tasks - some triggered twice and some missed"

To view the discussion, visit: https://community.jboss.org/message/792814#792814

--------------------------------------------------------------
Debugging the code - it seems +*SchedulerThreadPool*+ in +*JDKTimerService*+ is getting instantiated multiple times for some sessions and jobs getting scheduled twice.
As a work around we registered our own +*TimerService*+ and made this +*SchedulerThreadPool*+ static to get instanatiated only once (one SchedulerThreadPool per JVM) & made the pool size configurable.

Refer to https://community.jboss.org/message/741461#741461 https://community.jboss.org/message/741461 to register your own timer service.


private static ScheduledThreadPoolExecutor scheduler;

..........................................

public MyTimerService(int size) {
        getSchedularInstance(size);
    }

private ScheduledThreadPoolExecutor getSchedularInstance(int size) {
        if(scheduler == null) {
            this.scheduler = new ScheduledThreadPoolExecutor( size );
       } else {
            System.out.println(" returning the old scheduler ...");
        }

        return this.scheduler;
    }
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/792814#792814]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
tmag
2013-01-19 19:41:06 UTC
Permalink
tmag [https://community.jboss.org/people/tmag] created the discussion

"Re: Multiple Sessions - Timer Tasks - some triggered twice and some missed"

To view the discussion, visit: https://community.jboss.org/message/793026#793026

--------------------------------------------------------------
Seems there are multiple problems - for repeating timer tasks in regular intervals.

1. Sometimes multiple instances of ScheduledThreadPool objects getting created on single session - which we tried to avoid by making scheduler static as above.
2. ProcessContext data getting corrupted with duplicate process instance info.
When we print out the session & process info from context  in our registered custom timer service  - its showing duplicate process instance ids as shown below.

+*ProcessJobContext processJobContext = (ProcessJobContext) ctx;*+
+*StatefulKnowledgeSessionImpl ksessionImpl = (StatefulKnowledgeSessionImpl) processJobContext.getKnowledgeRuntime();*+
+*System.out.println("**********>session id : "+ ksessionImpl.getId() + "; process id : "+ processJobContext.getProcessInstanceId());*+


**********> session id : 0; process id : 6
**********> session id : 0; process id : 7
**********> session id : 0; process id : 8
**********> session id : 0; process id : 9
**********> session id : 0; process id : 10
......................

**********> session id : 0; process id : 6
**********> session id : 0; process id : 7
**********> session id : 0; process id : 8
**********> session id : 0; process id : 9
**********> session id : 0; process id : 10

These processes 6 to 10 are getting scheduled twice & executing twice.+*
*+
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793026#793026]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-01-21 09:10:45 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: Multiple Sessions - Timer Tasks - some triggered twice and some missed"

To view the discussion, visit: https://community.jboss.org/message/793181#793181

--------------------------------------------------------------
one thing that can lead into such situation is when you do not dispose session and then load it once again. That will mean you have two sessions (of the same id) loaded twice and thus timers will be fired twice.

HTH
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793181#793181]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
tmag
2013-01-21 12:53:30 UTC
Permalink
tmag [https://community.jboss.org/people/tmag] created the discussion

"Re: Multiple Sessions - Timer Tasks - some triggered twice and some missed"

To view the discussion, visit: https://community.jboss.org/message/793228#793228

--------------------------------------------------------------
that means...I can dispose a session and reload it again? The timers will resume on reload? Our understanding is that - once we dispose a session, it cannot be reused.

We have multiple sessions with timer tasks. On server reboot (say server crashed) we are reloading all sessions to restore timers. For initial 6 to 7 reboots everything seems fine. This issue happening after that. How can we overcome this? Please help.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793228#793228]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-01-21 14:23:46 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: Multiple Sessions - Timer Tasks - some triggered twice and some missed"

To view the discussion, visit: https://community.jboss.org/message/793255#793255

--------------------------------------------------------------
Correct, you can dispose and the reload the session at any time. Once session is reloaded all timers are reinitialized and in case of some missed fires such timers will be executed almost directly after session is reloaded.

Most important is to have only single session that runs given timers so in clustered environment that is bit tricky as you need to keep track of what timers are active on what session. There are efforts to provide more cluster friendly timer support and hopefully it will be soon available.

HTH
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793255#793255]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Manjeet Singh
2013-01-23 04:47:10 UTC
Permalink
Manjeet Singh [https://community.jboss.org/people/bpm77] created the discussion

"Re: Multiple Sessions - Timer Tasks - some triggered twice and some missed"

To view the discussion, visit: https://community.jboss.org/message/793645#793645

--------------------------------------------------------------
according to your suggestion, some missed fires will be executed after session is loaded.but in my case it's never be called.
I have three sessions 1,2,3 and created instances p1,p2,p3 on session 1,  Once session were active all threeprocess  timertasks were fired and showing session id 1 and three process context with process id p1,p2,p3.
Now restarted server, in JDKTimerService schedulejob , it is always showing sessioid 0 with correct process instance id p1,p2,p3 and timertasks running fine.
Now I have stopped java application and created new session id 2 and created process instances p4,p5,p6 on session2.
similiarly stopped application and  created p7,p8,p9 on sessiod id 3.
Now I have loaded all three sessions 1,2,3
timertask with delayed of 1 minute.
I can see instances are running multilple time , it seems like each session is running for  p1 to p9 and but behavior is not consistent.
sometime missing fire never runs ,sometime p1 is running for 4 times some p5...but in schedule jo session id is always 0(after startup)
I have table where I am storing session vs processinstanceid but dont know how to keep track of active timers.Is active timers are active processinstace?
Please help on this , stuck on this for days now.
Your suggestion is highly appreciated..
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793645#793645]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
tmag
2013-01-29 19:53:48 UTC
Permalink
tmag [https://community.jboss.org/people/tmag] created the discussion

"Re: Multiple Sessions - Timer Tasks - some triggered twice and some missed"

To view the discussion, visit: https://community.jboss.org/message/795001#795001

--------------------------------------------------------------
jBPM 5.4 seems to have some issues with
drools-compiler-5.5.0.Final.jar
drools-core-5.5.0.Final.jar
drools-persistence-jpa-5.5.0.Final.jar

When you have multiple sessions - its triggering timer tasks repeatedly & some timer tasks even miss.
If you replace these three jars with jBPM 5.3 ones - then it looks ok.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/795001#795001]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...