<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Re: Multiple ksession dispose issue
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/sanket.mohile">Sanket Mohile</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/810689#810689">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Thought to dig more into this..... And finally found my culprit.... And a temporary solution to it....</p><p>Here is all of it :-</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>1. This "WARN" msg would come only in case of a process with a timer node.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>2. After some more investigation, found that on each timer tick "<span style="color: #3366ff;">org.drools.persistence.jpa.JDKCallableJobCommand</span>" gets executed by JpaTimerJobInstance and it returns me <span style="color: #3366ff;">CommandService </span>of the disposed ksession. Hence the WARN message. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><table border="1" cellpadding="3" cellspacing="0" class="jiveBorder" style="width: 100%; border: 1px solid #000000;"><tbody><tr><th align="center" style="border:1px solid black;border: 1px solid #000000;background-color: #6690bc;" valign="middle"><span style="color: #ffffff;"><strong>org.drools.persistence.jpa.JpaTimerJobInstance.java</strong></span></th></tr><tr><td style="border:1px solid black;border: 1px solid #000000;"><p class="line" id="LC30" style="padding: 0px 0px 0px 10px;">...</p><p class="line" style="padding: 0px 0px 0px 10px;">...</p><p class="line" style="padding: 0px 0px 0px 10px;"><span class="kd" style="font-weight: bold;">public</span> <span class="n">Void</span> <span class="nf" style="color: #990000; font-weight: bold;">call</span><span class="o" style="font-weight: bold;">()</span> <span class="kd" style="font-weight: bold;">throws</span> <span class="n">Exception</span> <span class="o" style="font-weight: bold;">{</span></p><p class="line" id="LC31" style="padding: 0px 0px 0px 10px;">        <span class="k" style="font-weight: bold;">try</span> <span class="o" style="font-weight: bold;">{</span> </p><p class="line" id="LC32" style="padding: 0px 0px 0px 10px;">            <span class="n">JDKCallableJobCommand</span> <span class="n">command</span> <span class="o" style="font-weight: bold;">=</span> <span class="k" style="font-weight: bold;">new</span> <span class="n">JDKCallableJobCommand</span><span class="o" style="font-weight: bold;">(</span> <span class="k" style="font-weight: bold;">this</span> <span class="o" style="font-weight: bold;">);</span></p><p class="line" style="padding: 0px 0px 0px 10px;"><span class="o" style="font-weight: bold;"><span style="color: #339966;">             /* The following line returns me the command service object of the disposed ksession */</span><br/></span></p><p class="line" id="LC33" style="padding: 0px 0px 0px 10px;">            <span style="color: #ff0000;"><strong><span class="n">CommandService</span> <span class="n">commandService</span> <span class="o">=</span> <span class="o">((</span><span class="n">AcceptsTimerJobFactoryManager</span><span class="o">)</span><span class="n">scheduler</span><span class="o">).</span><span class="na">getTimerJobFactoryManager</span><span class="o">().</span><span class="na">getCommandService</span><span class="o">();</span></strong></span></p><p class="line" id="LC34" style="padding: 0px 0px 0px 10px;">            <span class="n">commandService</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">execute</span><span class="o" style="font-weight: bold;">(</span> <span class="n">command</span> <span class="o" style="font-weight: bold;">);</span></p><p class="line" id="LC35" style="padding: 0px 0px 0px 10px;">            <span class="k" style="font-weight: bold;">return</span> <span class="kc" style="font-weight: bold;">null</span><span class="o" style="font-weight: bold;">;</span></p><p class="line" id="LC36" style="padding: 0px 0px 0px 10px;">        <span class="o" style="font-weight: bold;">}</span> <span class="k" style="font-weight: bold;">catch</span><span class="o" style="font-weight: bold;">(</span> <span class="n">Exception</span> <span class="n">e</span> <span class="o" style="font-weight: bold;">)</span> <span class="o" style="font-weight: bold;">{</span> </p><p class="line" id="LC37" style="padding: 0px 0px 0px 10px;">            <span class="n">logger</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">error</span><span class="o" style="font-weight: bold;">(</span><span class="s" style="color: #dd1144;">"Unable to execute timer job!"</span><span class="o" style="font-weight: bold;">,</span> <span class="n">e</span><span class="o" style="font-weight: bold;">);</span></p><p class="line" id="LC38" style="padding: 0px 0px 0px 10px;">            <span class="k" style="font-weight: bold;">throw</span> <span class="n">e</span><span class="o" style="font-weight: bold;">;</span></p><p class="line" id="LC39" style="padding: 0px 0px 0px 10px;">        <span class="o" style="font-weight: bold;">}</span></p><p class="line" id="LC40" style="padding: 0px 0px 0px 10px;">    <span class="o" style="font-weight: bold;">}</span></p><p>  ...</p><p>   ...</p></td></tr></tbody></table><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Reason? - Probably because we use the same <span style="color: #3366ff;">SessionConfiguration </span>to load both our session....<span style="text-decoration: underline;"><strong> Ref:</strong></span> Read Comment by "<em>Sebastian Calbaza</em>" on <a class="jive-link-external-small" href="https://issues.jboss.org/browse/JBPM-3827">https://issues.jboss.org/browse/JBPM-3827</a> </p><p>So even after I dispose my ksession, the related <strong style="text-decoration: underline;">SingleSessionCommandService is still active</strong> somewhere with a dead ksession. And the <span style="color: #3366ff;">TimerJobFactoryManager </span>class hits me with it <span> :( </span></p><p>Please raise a JIRA if you guys think this is an issue.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>3. <span style="text-decoration: underline;">The Workaround</span>: In <span style="color: #3366ff;">CMTDisposeCommand </span>Class..... In the after completion method... set the <span style="color: #3366ff;">CommandService </span>object of the disposing ksession to the <span style="color: #3366ff;">CommandService </span>object of the ksession which is alive(The one you dont dispose because it has timers running on it....)</p><table border="1" cellpadding="3" cellspacing="0" class="jiveBorder" style="width: 100%; border: 1px solid #000000;"><tbody><tr><th align="center" style="border:1px solid black;border: 1px solid #000000;background-color: #6690bc;" valign="middle"><span style="color: #ffffff;"><strong>CMTDisposeCommand.java</strong></span></th></tr><tr><td style="border:1px solid black;border: 1px solid #000000;"><p>...</p><p>...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                <span style="color: #808080;">@Override</span></p><p>                public void <strong style="color: #800000;">afterCompletion</strong>(<span style="color: #3366ff;">int </span>status) {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                      <span style="color: #339966;">/* Set the Command Service of this ksession to one in which timer process started */</span></p><p>                      <span style="color: #3366ff;">SingleSessionCommandService </span>commandService = (<span style="color: #3366ff;">SingleSessionCommandService</span>)((<span style="color: #3366ff;">CommandBasedStatefulKnowledgeSession</span>)ksession).getCommandService();</p><p>                      <span style="color: #3366ff;">InternalKnowledgeRuntime </span>ikr = (<span style="color: #3366ff;">InternalKnowledgeRuntime</span>)commandService.getStatefulKnowledgeSession();</p><p>                      <span style="color: #3366ff;">JDKTimerService </span>timerService = (<span style="color: #3366ff;">JDKTimerService</span>)ikr.getTimerService();</p><p>                      <span style="color: #3366ff;">JpaTimeJobFactoryManager </span>manager = (<span style="color: #3366ff;">JpaTimeJobFactoryManager</span>)timerService.getTimerJobFactoryManager();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                      <span style="color: #3366ff;">SingleSessionCommandService </span>ksession2CommandService = (<span style="color: #3366ff;">SingleSessionCommandService</span>((<span style="color: #3366ff;">CommandBasedStatefulKnowledgeSession</span>)ksession2).getCommandService();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                      manager.setCommandService(ksession2CommandService);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                      <span style="color: #339966;">/* Now dispose the ksession */</span></p><p>                       ksession1.dispose()</p><p>                }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>...</p><p>...</p></td></tr></tbody></table><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Now this solves the issue I'd report in this thread. </p><p>Not a good option though, ideally the <span style="color: #3366ff;">TimerJobFactoryManager</span> should not return me a <span style="color: #3366ff;">SingleSessionCommandService </span>reference with a disposed ksession.</p><p>I'll mark this as answered. But please let me know if there are better fixes/steps or I'm missing something.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Thanks,</p><p>Sanket</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/810689#810689">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>