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).
public class KnowledgeSessionThread extends Thread {
int iterations = 500;
int numberFacts = 1000;
private ObjectPool pool;
public KnowledgeSessionThread(ObjectPool pool) throws Exception {
this.pool = pool;
}
public void run() {
try {
for( int i = 0; i < iterations; i++ ) {
StatefulKnowledgeSession session =
(StatefulKnowledgeSession)pool.borrowObject();
for( int j = 0; j < numberFacts; j++ ) {
Message msg = new Message();
msg.setMessage("Hello world");
msg.setStatus(Message.HELLO);
session.insert(msg);
}
session.fireAllRules();
pool.returnObject(session);
}
System.out.println("Thread finished " +
this.currentThread().getName());
} catch( Exception e ) {
e.printStackTrace();
}
}
}
@Override
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-e...
Sent from the Drools: User forum mailing list archive at
Nabble.com.