JBoss Community

Re: Multiple ksession dispose issue

created by Sanket Mohile in jBPM - View the full discussion

Thought to dig more into this..... And finally found my culprit.... And a temporary solution to it....

Here is all of it :-

 

1. This "WARN" msg would come only in case of a process with a timer node.

 

2. After some more investigation, found that on each timer tick "org.drools.persistence.jpa.JDKCallableJobCommand" gets executed by JpaTimerJobInstance and it returns me CommandService of the disposed ksession. Hence the WARN message.

 

org.drools.persistence.jpa.JpaTimerJobInstance.java

...

...

public Void call() throws Exception {

        try {

            JDKCallableJobCommand command = new JDKCallableJobCommand( this );

             /* The following line returns me the command service object of the disposed ksession */

            CommandService commandService = ((AcceptsTimerJobFactoryManager)scheduler).getTimerJobFactoryManager().getCommandService();

            commandService.execute( command );

            return null;

        } catch( Exception e ) {

            logger.error("Unable to execute timer job!", e);

            throw e;

        }

    }

  ...

   ...

 

Reason? - Probably because we use the same SessionConfiguration to load both our session.... Ref: Read Comment by "Sebastian Calbaza" on https://issues.jboss.org/browse/JBPM-3827

So even after I dispose my ksession, the related SingleSessionCommandService is still active somewhere with a dead ksession. And the TimerJobFactoryManager class hits me with it :(

Please raise a JIRA if you guys think this is an issue.

 

3. The Workaround: In CMTDisposeCommand Class..... In the after completion method... set the CommandService object of the disposing ksession to the CommandService object of the ksession which is alive(The one you dont dispose because it has timers running on it....)

CMTDisposeCommand.java

...

...

 

                @Override

                public void afterCompletion(int status) {

 

                      /* Set the Command Service of this ksession to one in which timer process started */

                      SingleSessionCommandService commandService = (SingleSessionCommandService)((CommandBasedStatefulKnowledgeSession)ksession).getCommandService();

                      InternalKnowledgeRuntime ikr = (InternalKnowledgeRuntime)commandService.getStatefulKnowledgeSession();

                      JDKTimerService timerService = (JDKTimerService)ikr.getTimerService();

                      JpaTimeJobFactoryManager manager = (JpaTimeJobFactoryManager)timerService.getTimerJobFactoryManager();

 

                      SingleSessionCommandService ksession2CommandService = (SingleSessionCommandService((CommandBasedStatefulKnowledgeSession)ksession2).getCommandService();

 

                      manager.setCommandService(ksession2CommandService);

 

                      /* Now dispose the ksession */

                       ksession1.dispose()

                }

 

...

...

 

Now this solves the issue I'd report in this thread.

Not a good option though, ideally the TimerJobFactoryManager should not return me a SingleSessionCommandService reference with a disposed ksession.

I'll mark this as answered. But please let me know if there are better fixes/steps or I'm missing something.

 

Thanks,

Sanket

Reply to this message by going to Community

Start a new discussion in jBPM at Community