Why should newStatefulKnowledgeSession, which merely *creates* a StatefulKnowledgeSession object from a KnowledgeBase, be able to run in parallel with calls to the same method? It&#39;s a lightweight operation, not taking long, and the KnowledgeBase must be protected for a short time to avoid confusion in its internal data structures.<br>
<br>-W<br><br><br><div class="gmail_quote">2011/10/11 Juan Carlos Fernández <span dir="ltr">&lt;<a href="mailto:juancarlos.fernandez@safelayer.com">juancarlos.fernandez@safelayer.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;">
Hi all,<br>
<br>
Try to execute many threads with the next source code (simple simple code).<br>
You will see that only one CPU-thread is used in a mutithreaded CPU system.<br>
It seems to be a system lock inside newStatefulKnowledgeSession().<br>
<br>
This is a big disappoint because we can&#39;t use StatefulKnowledgeSession in<br>
multithreaded environment. All is executing sequentially because of this<br>
problem. Yes, we can asure newStatefulKnowledgeSession() is multithread (no<br>
error is returned) but we can&#39;t asure newStatefulKnowledgeSession() executes<br>
in parallel.<br>
<br>
Do you know any problem about this?<br>
<br>
Thank&#39;s in advance<br>
<br>
PROBLEMATIC SOURCE CODE:<br>
<br>
public class KnowledgeSessionThread extends Thread {<br>
        private static final int ITERATIONS = 1000000;<br>
        private KnowledgeBase kbase;<br>
<br>
    public KnowledgeSessionThread() throws Exception {<br>
                kbase = readKnowledgeBase();<br>
    }<br>
<br>
    public void run() {<br>
                try {<br>
                        for( int i = 0; i &lt; ITERATIONS; i++ ) {<br>
                                StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();<br>
                                session.dispose();<br>
                        }<br>
                        System.out.println(&quot;Thread finished&quot;);<br>
                } catch( Exception e ) {<br>
                        e.printStackTrace();<br>
                }<br>
    }<br>
<br>
    private KnowledgeBase readKnowledgeBase() throws Exception {<br>
        KnowledgeBuilder kbuilder =<br>
KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
        kbuilder.add(ResourceFactory.newClassPathResource(&quot;Sample.drl&quot;),<br>
ResourceType.DRL);<br>
        kbuilder.add(ResourceFactory.newClassPathResource(&quot;Sample.bpmn&quot;),<br>
ResourceType.BPMN2);<br>
        KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
        if (errors.size() &gt; 0) {<br>
            for (KnowledgeBuilderError error: errors) {<br>
                System.err.println(error);<br>
            }<br>
            throw new IllegalArgumentException(&quot;Could not parse<br>
knowledge.&quot;);<br>
        }<br>
        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();<br>
        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
        return kbase;<br>
    }<br>
}<br>
<font color="#888888"><br>
<br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p3412107.html" target="_blank">http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p3412107.html</a><br>

Sent from the Drools: User forum 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>