<br>   Hi,<br><br>   I fixed a problem related to deadlock when sharing packages among multiple kbases a couple weeks ago. Not sure if it is the same, but try trunk and let me know, plz.<br><br>   Meanwhile, I am curious why you can&#39;t simply create a kbase with all your rules and share the kbase among all your requests, just creating one session per request? <br>
<br>    Reason is that adding packages to a kbase for each request still adds unnecessary overhead to your application, and kbases are designed to be shared in such cases. If you need to orchestrate multiple execution paths for your rules, you could use rule flow or any other coordination mechanism. Finally, Rete is known by performing really well with increasing number of rules, since the performance is not dependent on the number of existing rules, but on the number of affected constraints.<br>
<br>   Just my .02c<br><br>   Edson<br><br><br><div class="gmail_quote">2009/12/22 malkhafaji <span dir="ltr">&lt;<a href="mailto:moe.alkhafaji@medcpu.com">moe.alkhafaji@medcpu.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>
I am trying to create multiple sessions, and for each session I will load<br>
one knowledge package representing one drl. Each drl may optionally load<br>
additional knowledge packages (drls). Since all sessions will be accessing<br>
the same list of knowledge packages, and since they take a long time to<br>
compile resources, I decided to create a Map with all possible knowledge<br>
packages that all sessions may use. That worked beautifully saving me<br>
compilation time (it is done at start up).<br>
<br>
Now, here is how I am creating the static map:<br>
<br>
private static ConcurrentMap&lt;String, KnowledgePackage&gt; knowledgePackages =<br>
new<br>
                ConcurrentHashMap&lt;String, KnowledgePackage&gt;();<br>
<br>
Here is how I am initializing it:<br>
<br>
                KnowledgeBuilder kbuilder = null;<br>
<br>
                for (MedCPUKnowledgeBase medcpuKnowledgeBase : medcpuKnowledgeBases) {<br>
                        try {<br>
                                kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
<br>
                                // This call actually compiles the drl file.<br>
<br>
kbuilder.add(ResourceFactory.newClassPathResource(medcpuKnowledgeBase.getFileName()),<br>
<div class="im">                                                ResourceType.DRL);<br>
<br>
                                KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
<br>
                                if (errors.size() &gt; 0) {<br>
</div>                                        .....<br>
                                } else {<br>
                                        knowledgePackages.put(medcpuKnowledgeBase.getFileName(),<br>
                                                        [the package just added above]);<br>
                                }<br>
                        } catch(Exception ex) {<br>
                                ....<br>
                                } else {<br>
                                        .....<br>
                                }<br>
                        }<br>
                }<br>
<br>
<br>
Each session will do this to get the pre-compiled KnowledgePackage:<br>
<br>
KnowledgePackage knowledgePackage = knowledgePackages.get(kb);<br>
......<br>
Collection&lt;KnowledgePackage&gt; packages = new ArrayList&lt;KnowledgePackage&gt;();<br>
packages.add(knowledgePackage);<br>
<br>
// The problem is this guy (after a relatively small number of requests each<br>
opening a new session) just gets stuck!! It does not throw an exception and<br>
it does not return.<br>
this.knowledgeBase.addKnowledgePackages(packages);<br>
<br>
When I did not share the KnowledgePackages like I did above, I was able to<br>
get thousands of requests with each having its own session, knowledgebase,<br>
and its own knowledge packages after they compile the respective drls.<br>
However, because this was slow compiling the same drls over and over again I<br>
switched to the design above which after only 20 or 30 requests it gets<br>
stuck on the line above. I still have a knowledgebase per session per<br>
request, but now I am sharing the knowledge packages.<br>
<br>
I cannot find anywhere where it says that KnowledgePackage objects are not<br>
thread-safe (not safe to be shared between sessions/threads). Any idea why I<br>
am stuck on the line above? Thanks!<br>
<font color="#888888">--<br>
View this message in context: <a href="http://n3.nabble.com/Sessions-Sharing-KnowledgeBase-tp96894p96894.html" target="_blank">http://n3.nabble.com/Sessions-Sharing-KnowledgeBase-tp96894p96894.html</a><br>
</font><div><div></div><div class="h5">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>
</div></div></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>