<br>   I believe this problem is fixed in trunk already. Would you please try your own use case, just in case?<br><br>   Thanks,<br>      Edson<br><br><div class="gmail_quote">2010/2/8 heldeen <span dir="ltr">&lt;<a href="mailto:heldeen@overstock.com">heldeen@overstock.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
Hello,<br>
<br>
Using Drools 5.1.0.M1.<br>
I am running into a blocking problem when I concurrently try to update a<br>
fact in my knowledge session, which is fireUntilHalt() in its own thread,<br>
from another thread, an updator thread. I know that only these 2 threads are<br>
ever accessing each knowledge session.<br>
<br>
Has anyone else run into this problem?<br>
<br>
I am including the relavant details and can provide a working example if<br>
need be. The block happens randomly anywhere from 20 - 1000&#39;s of sessions.<br>
<br>
I consistantly get this stack trace from the blocked thread:<br>
org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1540)<br>
org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1529)<br>
org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1403)<br>
org.drools.impl.StatefulKnowledgeSessionImpl.update(StatefulKnowledgeSessionImpl.java:248)<br>
...<br>
<br>
I have a simple drools knowledge base that is a basic rule flow [Start -&gt;<br>
Rule Flow Group -&gt; Event Wait -&gt; Rule Flow Group -&gt; End]<br>
<br>
I build a knowledge base like this:<br>
<br>
      KnowledgeBaseConfiguration knowledgeBaseConfiguration =<br>
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
      knowledgeBaseConfiguration.setOption(AssertBehaviorOption.EQUALITY);<br>
      knowledgeBaseConfiguration.setOption(MBeansOption.ENABLED);<br>
<br>
      KnowledgeBase knowledgeBase =<br>
KnowledgeBaseFactory.newKnowledgeBase(knowledgeBaseConfiguration);<br>
<br>
      KnowledgeBuilder kbuilder =<br>
KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
      kbuilder.add(ResourceFactory.newClassPathResource(CHANGE_SET_XML,<br>
getClass()), ResourceType.CHANGE_SET);<br>
      if (kbuilder.hasErrors()) {<br>
        throw new IllegalArgumentException(&quot;Unable to build knowledge&quot;);<br>
      }<br>
      knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
<br>
<br>
My basic test fact is:<br>
<br>
public class Fact() {<br>
<br>
  String name;<br>
  boolean isReady;<br>
<br>
  //getters and setters<br>
}<br>
<br>
I have a fixed thread pool (Sun&#39;s ExecutorService.newFixedThreadPool() with<br>
20 threads). Each session is submitted from a for loop of 0 to 100000 where<br>
it generates a simple fact with Fact.name = &quot;fact&quot;+i and Fact.isReady =<br>
false, then puts it in an array like so:<br>
final Object[] facts...<br>
fixedPoolExecutor.submit(new Runnable() {<br>
  @Override<br>
  public void run() {<br>
    StatefulKnowledgeSession knowledgeSession = null;<br>
    try {<br>
      knowledgeSession = knowledgeBase.newStatefulKnowledgeSession();<br>
      //put it in a ConcurrentHashMap keyed by session id.<br>
      ...<br>
      for (Object fact : facts) {<br>
        knowledgeSession.insert(fact);<br>
      }<br>
<br>
      //add session completion halt event - omiting other unused methods<br>
      knowledgeSession.addEventListener(new ProcessEventListener() {<br>
<br>
        @Override<br>
        public void afterProcessCompleted(ProcessCompletedEvent event) {<br>
          knowledgeSession.halt();<br>
        }<br>
      });<br>
<br>
      knowledgeSession.startProcess(PROCESS_ID);<br>
<br>
      knowledgeSession.fireUntilHalt();<br>
    } finally {<br>
      if (knowledgeSession != null) {<br>
        knowledgeSession.dispose();<br>
      }<br>
    }<br>
});<br>
<br>
I have a single thread executor (Sun&#39;s<br>
ExecutorService.newSingleThreadExecutor()) that is used to update these<br>
sessions (basically set the Fact.isReady from false to true for the<br>
EventWait in my rule flow):<br>
<br>
final int sessionId...<br>
final Object[] facts...<br>
singleThreadExecutor.submit(new Runnable() {<br>
  @Override<br>
  public void run() {<br>
    StatefulKnowledgeSession knowledgeSession = null;<br>
    try {<br>
      knowledgeSession = ... from ConcurrentHashMap based on sessionId<br>
<br>
      FactHandle factHandle = knowledgeSession.getFactHandle(fact);<br>
      if (null != factHandle) {<br>
        knowledgeSession.update(factHandle, fact);//This is where it blocks<br>
and never returns<br>
      } else {<br>
        knowledgeSession.insert(fact);<br>
      }<br>
});<br>
<br>
-Heath<br>
<font color="#888888">--<br>
View this message in context: <a href="http://n3.nabble.com/StatefulKnowledgeSession-synchronization-problem-tp195744p195744.html" target="_blank">http://n3.nabble.com/StatefulKnowledgeSession-synchronization-problem-tp195744p195744.html</a><br>

Sent from the Drools - User mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>