Its just a hunch, but try your original code (not the pooling one) but pass the newStatefulKnowledgeSession to the constructor of the Thread sublass.<br>-W<br><br><br><div class="gmail_quote">2011/10/11 Juan Carlos Fernández <span dir="ltr"><<a href="mailto:juancarlos.fernandez@safelayer.com">juancarlos.fernandez@safelayer.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Here you have my pooling solution. Testing this source code reaches 100% CPU<br>
usage!! Used apache commons pooling. borrowObject() creates stateful session<br>
and pool it. returnObject() retracts all facts.<br>
<br>
Can we extract a conclusion with my tests? I'm going to implement pooling<br>
solution inside my SOAP app and do performance tests (throughput).<br>
<div class="im"><br>
public class KnowledgeSessionThread extends Thread {<br>
<br>
</div> int iterations = 500;<br>
int numberFacts = 1000;<br>
private ObjectPool pool;<br>
<br>
public KnowledgeSessionThread(ObjectPool pool) throws Exception {<br>
this.pool = pool;<br>
<div class="im"> }<br>
<br>
public void run() {<br>
try {<br>
for( int i = 0; i < iterations; i++ ) {<br>
StatefulKnowledgeSession session =<br>
</div>(StatefulKnowledgeSession)pool.borrowObject();<br>
<div class="im"> for( int j = 0; j < numberFacts; j++ ) {<br>
Message msg = new Message();<br>
msg.setMessage("Hello world");<br>
msg.setStatus(Message.HELLO);<br>
session.insert(msg);<br>
}<br>
session.fireAllRules();<br>
</div> pool.returnObject(session);<br>
<div class="im"> }<br>
System.out.println("Thread finished " +<br>
this.currentThread().getName());<br>
} catch( Exception e ) {<br>
e.printStackTrace();<br>
}<br>
}<br>
}<br>
<br>
</div> @Override<br>
public Object makeObject() throws Exception {<br>
System.out.println(Thread.currentThread().getName() + " - makeObject()<br>
called" );<br>
return kbase.newStatefulKnowledgeSession();<br>
}<br>
<br>
@Override<br>
public void destroyObject( Object obj ) {<br>
StatefulKnowledgeSession session = (StatefulKnowledgeSession)obj;<br>
session.dispose();<br>
<br>
}<br>
<br>
@Override<br>
public void passivateObject(Object obj) {<br>
StatefulKnowledgeSession session = (StatefulKnowledgeSession)obj;<br>
for( FactHandle handle : session.getFactHandles() ) {<br>
session.retract(handle);<br>
}<br>
}<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p3412338.html" target="_blank">http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p3412338.html</a><br>
</font><div><div></div><div class="h5">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>
</div></div></blockquote></div><br>