Hi all,<br><br>   We&#39;ve been for long time now developing a complex event processing system that ( simplified version ahead !! ) involves a set of rules that in turn activates a set processes that fulfill human tasks and other kind of tasks.. This all is running in a StatefulKnowledgeSession with JPA persistence configured both for Drools and JBPM. We are running an stack of Drools, JBPM, Drools Integration, Drools fussion, etc..<br>

<br>   We&#39;ve been able to persist Drools sessions &amp; JBPM processes in the same Persistence Context  ( not without pain :( ) using different JTA implementations including ( but not limited to ) Bitronix &amp; Atomikos.<br>

<br>    What we are observing here is what seems to be some kind of race 
condition between Drools and JBPM when running the knowledge session when JPA&amp;JTA persistence is configured. Very often, as soon as after 2-3 
processes get created as rule&#39;s consequences are fired in response of events inside the session we see how JBPM finds its instance nullified by Drools when
 it tries to end a process and persist it.<br><br>   We&#39;ve been able to find where Drools decides to delete an instance of the process ... at a given time Drools executes JPAProcessInstanceManager.clearProcessInstances() [1] when it finalizes a SingleSessionCommand wich in turn calls disconnect() for *all* the local-stored processinstances ( wich gets populated with instances of processes every time a process is started in the knowledge session ):<br>

<br><pre><div class="line" id="LC115">    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">clearProcessInstances</span><span class="o">()</span> <span class="o">{</span></div><div class="line" id="LC116">

        <span class="k">for</span> <span class="o">(</span><span class="n">ProcessInstance</span> <span class="nl">processInstance:</span> <span class="k">new</span> <span class="n">ArrayList</span><span class="o">&lt;</span><span class="n">ProcessInstance</span><span class="o">&gt;(</span><span class="n">processInstances</span><span class="o">.</span><span class="na">values</span><span class="o">()))</span> <span class="o">{</span></div>

<div class="line" id="LC117">            <span class="o">((</span><span class="n">ProcessInstanceImpl</span><span class="o">)</span> <span class="n">processInstance</span><span class="o">).</span><span class="na">disconnect</span><span class="o">();</span></div>

<div class="line" id="LC118">        <span class="o">}</span></div><div class="line" id="LC119">    <span class="o">}</span></div></pre>    <br>    So, Drools decides to disconnect all process instances in it&#39;s JPA context without taking in account the state the process is in, and when an processinstance that is not stopped gets removed then JBPM finds it&#39;s NullPointerException...<br>

<br>    We&#39;ve modified the code to make Drools aware of the state of the process before wiping it from the context   ( no problem here, there will be no leak as a running processinstance will be removed in future calls of &quot;clearProcessInstances&quot; given the process is closed ). But unfortunatelly this seems to resolve this problem, but lots of other problems ( wich seems also race conditions arise :  for instance: Drools closes connections to the database and JBPM finds the connection closed, <br>

<br><br>    So, we are really worried about using Drools &amp; JBPM in a persisted environment. Maybe our asumptions are wrong...  Is it possible to have an scenario like ours given the current Drools &amp; JBPM integration status for a persistent statefulKnowledge Session?  Did anyone build a complex event processing system like ours in a unaltered persistence environment such as provided in Drools and JBPM by default?<br>

<br><br>Greets,<br><br>[1] <a href="https://github.com/droolsjbpm/jbpm/blob/master/jbpm-persistence-jpa/src/main/java/org/jbpm/persistence/processinstance/JPAProcessInstanceManager.java">https://github.com/droolsjbpm/jbpm/blob/master/jbpm-persistence-jpa/src/main/java/org/jbpm/persistence/processinstance/JPAProcessInstanceManager.java</a><br>

<br><br><br><br><br><br clear="all">Alberto R. Galdo<br><a href="mailto:argaldo@gmail.com" target="_blank">argaldo@gmail.co</a><br>