<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Has anyone run into this issue?&nbsp; I&#8217;ve found a couple other references to deadlocks but nothing that seems to match exactly what I&#8217;m seeing. I&#8217;m running with drools 5.1.1 and using the BatchExecutionCommand interface to feed a set of commands into my StatefulKnowledgeSession.&nbsp; I also have a simple rule that uses the duration attribute to clean up old facts.&nbsp; The problem is that the thread that executes the rule associated with the duration attribute acquires the lock associated with the DefaultAgenda class object and subsequently tries to acquire the locks managed by the AbstractWorkingMemory.&nbsp; However, my main thread that uses the BatchExecutionCommand interface could run while the other thread is running and this thread first acquires the AbstractWorkingMemory locks and later tries to acquire the DefaultAgenda class object lock resulting in the deadlock.<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>Here&#8217;s is the stack trace for the thread that runs when duration expires:<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>Unsafe.park(boolean, long) line: not available [native method] <br>LockSupport.park(Object) line: 158 <br>ReentrantLock$NonfairSync(AbstractQueuedSynchronizer).parkAndCheckInterrupt() line: 747 <br>ReentrantLock$NonfairSync(AbstractQueuedSynchronizer).acquireQueued(AbstractQueuedSynchronizer$Node, int) line: 778 <br>ReentrantLock$NonfairSync(AbstractQueuedSynchronizer).acquire(int) line: 1114 <br>ReentrantLock$NonfairSync.lock() line: 186 <br>ReentrantLock.lock() line: 262 <br>ReteooStatefulSession(AbstractWorkingMemory).retract(FactHandle, boolean, boolean, Rule, Activation) line: 1256 <br>DefaultKnowledgeHelper.retract(FactHandle) line: 201 <br>DefaultKnowledgeHelper.retract(Object) line: 214 <br>Rule_Automatically_Remove_Old_Events_0.defaultConsequence(KnowledgeHelper, Event, FactHandle) line: 10 <br>Rule_Automatically_Remove_Old_Events_0DefaultConsequenceInvoker.evaluate(KnowledgeHelper, WorkingMemory) line: 29 <br>DefaultAgenda.fireActivation(Activation) line: 917 <br>Scheduler$ActivationTimerJob.execute(JobContext) line: 73 <br>JDKTimerService$JDKCallableJob.call() line: 147 <br>JDKTimerService$JDKCallableJob.call() line: 125 <br>FutureTask$Sync.innerRun() line: 303 <br>ScheduledThreadPoolExecutor$ScheduledFutureTask&lt;V&gt;(FutureTask&lt;V&gt;).run() line: 138 <br>ScheduledThreadPoolExecutor$ScheduledFutureTask&lt;V&gt;.access$301(ScheduledThreadPoolExecutor$ScheduledFutureTask) line: 98 <br>ScheduledThreadPoolExecutor$ScheduledFutureTask&lt;V&gt;.run() line: 207 <br>ThreadPoolExecutor$Worker.runTask(Runnable) line: 886 <br>ThreadPoolExecutor$Worker.run() line: 908 <br>Thread.run() line: 619<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>And here&#8217;s the stack trace of the thread using the BatchExecutionCommand interface:<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>DefaultAgenda.fireActivation(Activation) line: 889 <br>DefaultAgenda.fireNextItem(AgendaFilter) line: 856 <br>DefaultAgenda.fireAllRules(AgendaFilter, int) line: 1071 <br>ReteooStatefulSession(AbstractWorkingMemory).fireAllRules(AgendaFilter, int) line: 785 <br>ReteooStatefulSession(AbstractWorkingMemory).fireAllRules() line: 751 <br>StatefulKnowledgeSessionImpl.fireAllRules() line: 218 <br>FireAllRulesCommand.execute(Context) line: 99 <br>FireAllRulesCommand.execute(Context) line: 33 <br>BatchExecutionCommandImpl.execute(Context) line: 159 <br>BatchExecutionCommandImpl.execute(Context) line: 81 <br>StatefulKnowledgeSessionImpl.execute(Context, Command&lt;T&gt;) line: 887 <br>StatefulKnowledgeSessionImpl.execute(Command&lt;T&gt;) line: 862 <br>Rules$RuleRunnerThread.run() line: 554<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>The rule with the duration attribute is very simple and included below:<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>rule &quot;Automatically Remove Old Events&quot;<o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp; agenda-group &quot;SYSTEM&quot;<o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp; // 1 hour (specified in milliseconds)<o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp; duration 3600000 <o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;when<o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $event : Event(eventId : id)<o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not SituationEvent(correlator == eventId)<o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp; then<o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retract($event);<o:p></o:p></p><p class=MsoNormal>end<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><span style='font-size:7.5pt;font-family:"Arial","sans-serif"'>CONFIDENTIALITY NOTICE: The information contained in this e-mail and its attachments are privileged and confidential and may contain proprietary, copyrighted or other legally protected information which is intended solely for the use of the addressee(s).&nbsp; If you are not the intended recipient, you are hereby notified that any disclosure, use, copying or distribution of this communication is strictly prohibited.&nbsp; Please notify the sender immediately and permanently delete this e-mail from your computer.<o:p></o:p></span></p><p class=MsoNormal><o:p>&nbsp;</o:p></p></div></body></html>