Its just a hunch, but try your original code (not the pooling one) but pass the newStatefulKnowledgeSession to the constructor of the Thread sublass.
-W
Here you have my pooling solution. Testing this source code reaches 100% CPU
usage!! Used apache commons pooling. borrowObject() creates stateful session
and pool it. returnObject() retracts all facts.
Can we extract a conclusion with my tests? I'm going to implement pooling
solution inside my SOAP app and do performance tests (throughput).
int iterations = 500;
public class KnowledgeSessionThread extends Thread {
int numberFacts = 1000;
private ObjectPool pool;
public KnowledgeSessionThread(ObjectPool pool) throws Exception {
this.pool = pool;
}(StatefulKnowledgeSession)pool.borrowObject();
public void run() {
try {
for( int i = 0; i < iterations; i++ ) {
StatefulKnowledgeSession session =
for( int j = 0; j < numberFacts; j++ ) {pool.returnObject(session);
Message msg = new Message();
msg.setMessage("Hello world");
msg.setStatus(Message.HELLO);
session.insert(msg);
}
session.fireAllRules();
}@Override
System.out.println("Thread finished " +
this.currentThread().getName());
} catch( Exception e ) {
e.printStackTrace();
}
}
}
public Object makeObject() throws Exception {
System.out.println(Thread.currentThread().getName() + " - makeObject()
called" );
return kbase.newStatefulKnowledgeSession();
}
@Override
public void destroyObject( Object obj ) {
StatefulKnowledgeSession session = (StatefulKnowledgeSession)obj;
session.dispose();
}
@Override
public void passivateObject(Object obj) {
StatefulKnowledgeSession session = (StatefulKnowledgeSession)obj;
for( FactHandle handle : session.getFactHandles() ) {
session.retract(handle);
}
}
--
View this message in context: http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p3412338.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users