<!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;">
timer job issues when disposing session in embedded j2ee process
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/umb71">umberto maguolo</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/824721#824721">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hi all,</p><p>i'm using jBPM 5.4,  I have a knowledge session with a process instance in it, embebbed in  an ejb with container managed transaction, the process definition has a timer intermediate event in it:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span></span></p><p>i'm using jpa persistence but the problem arises also with in memory session without persistence. I've utilized the CMTDisposeCommand class to register the synchronization with the transaction manager and implemented the afterCompletion method to be notified when the container finishes it's work committing the transaction; in the afterCompletion method i've utilized the DefaultProcessEventListener and implemented the afterProcessCompleted method  so i can (at least i thought it was so) dispose my knowledge session at the end of all the process elaboration. </p><p>The problem is that the process is regularly terminated but it seams that the timer service sheduler is not aware of that fact neither that the session is disposed and it continuosly try to signal the timer event on the session. When i call the ksession.dispose, in the afterProcessCompleted method, i get the exception in the server console:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>SEVERE: Error when executing timer job</p><p>java.lang.IllegalStateException: Illegal method call. This session was previously disposed.</p><p>        at org.drools.reteoo.DisposedReteooWorkingMemory.getLastIdleTimestamp(DisposedReteooWorkingMemory.java:562)</p><p>        at org.drools.impl.StatefulKnowledgeSessionImpl.getLastIdleTimestamp(StatefulKnowledgeSessionImpl.java:890)</p><p>        at org.drools.persistence.SingleSessionCommandService$EndOperationListenerImpl.endOperation(SingleSessionCommandService.java:334)</p><p>        at org.drools.common.AbstractWorkingMemory.endOperation(AbstractWorkingMemory.java:1365)</p><p>        at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1006)</p><p>        at org.drools.impl.StatefulKnowledgeSessionImpl.executeQueuedActions(StatefulKnowledgeSessionImpl.java:866)</p><p>        at org.jbpm.process.instance.event.DefaultSignalManager.signalEvent(DefaultSignalManager.java:90)</p><p>        at org.jbpm.process.instance.timer.TimerManager$ProcessJob.execute(TimerManager.java:323)</p><p>        at org.drools.time.SelfRemovalJob.execute(SelfRemovalJob.java:15)</p><p>        at org.drools.time.impl.DefaultTimerJobInstance.call(DefaultTimerJobInstance.java:51)</p><p>        at org.drools.persistence.jpa.JpaTimerJobInstance.internalCall(JpaTimerJobInstance.java:43)</p><p>        at org.drools.persistence.jpa.JDKCallableJobCommand.execute(JDKCallableJobCommand.java:20)</p><p>        at org.drools.persistence.jpa.JDKCallableJobCommand.execute(JDKCallableJobCommand.java:6)</p><p>        at org.drools.command.impl.DefaultCommandService.execute(DefaultCommandService.java:36)</p><p>        at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:373)</p><p>        at org.drools.persistence.jpa.JpaTimerJobInstance.call(JpaTimerJobInstance.java:34)</p><p>        at org.drools.persistence.jpa.JpaTimerJobInstance.call(JpaTimerJobInstance.java:14)</p><p>        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)</p><p>        at java.util.concurrent.FutureTask.run(FutureTask.java:166)</p><p>        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)</p><p>        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)</p><p>        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)</p><p>        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)</p><p>        at java.lang.Thread.run(Thread.java:722)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>giu 25, 2013 11:46:41 AM org.drools.time.impl.DefaultTimerJobInstance call</p><p>WARNING: Unable to execute timer job!</p><p>java.lang.IllegalStateException: Illegal method call. This session was previously disposed.</p><p>        at org.drools.reteoo.DisposedReteooWorkingMemory.getProcessInstance(DisposedReteooWorkingMemory.java:382)</p><p>        at org.drools.impl.StatefulKnowledgeSessionImpl.getProcessInstance(StatefulKnowledgeSessionImpl.java:297)</p><p>        at org.jbpm.process.instance.timer.TimerManager$ProcessJob.execute(TimerManager.java:335)</p><p>        at org.drools.time.SelfRemovalJob.execute(SelfRemovalJob.java:15)</p><p>        at org.drools.time.impl.DefaultTimerJobInstance.call(DefaultTimerJobInstance.java:51)</p><p>        at org.drools.persistence.jpa.JpaTimerJobInstance.internalCall(JpaTimerJobInstance.java:43)</p><p>        at org.drools.persistence.jpa.JDKCallableJobCommand.execute(JDKCallableJobCommand.java:20)</p><p>        at org.drools.persistence.jpa.JDKCallableJobCommand.execute(JDKCallableJobCommand.java:6)</p><p>        at org.drools.command.impl.DefaultCommandService.execute(DefaultCommandService.java:36)</p><p>        at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:373)</p><p>        at org.drools.persistence.jpa.JpaTimerJobInstance.call(JpaTimerJobInstance.java:34)</p><p>        at org.drools.persistence.jpa.JpaTimerJobInstance.call(JpaTimerJobInstance.java:14)</p><p>        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)</p><p>        at java.util.concurrent.FutureTask.run(FutureTask.java:166)</p><p>        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)</p><p>        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)</p><p>        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)</p><p>        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)</p><p>        at java.lang.Thread.run(Thread.java:722)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I've also tried to cancel any TimerJobInstance in the TimerService prior to dispose the session but the problem is still present. Am i doing something wrong? Missing something? What is the correct way of disposing session with (terminated) timer events in it?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Thanks.</p><p>Umberto</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/824721#824721">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>