[rules-users] StatefulKnowledgeSession construction executes sequentially (no multithread)

Juan Carlos Fernández juancarlos.fernandez at safelayer.com
Tue Oct 11 07:35:27 EDT 2011


Thank you for your responses,

Have a look to the 
http://drools.46999.n3.nabble.com/ksession-insert-executes-sequentially-in-multithreaded-StatefulKnowledgeSessions-td3399339.html
post  I wrote some days ago. You will see a complete test (no responses in
the forum). After I wrote the post, I looked inside drools source code and
tested that executing thousands internal "ObjectHashMap::put()" when calling
session.insert(fact) reached the same result (JMV memory management blocked
parallel execution and no more than one CPU thread was used).

I have tested lots of possibilities. This is the test source code you
request. Same result (one CPU thread used)... after creating some sessions,
I insert some facts. When I implement the test solution inside my SOAP
application, same result again (drools lock).

Ideas? I'm testing session pooling...

public class KnowledgeSessionThread extends Thread {
	
	private static final int iterations = 500;
	private static final int numberFacts = 1000;
	private KnowledgeBase base;
	
    public KnowledgeSessionThread(KnowledgeBase base) throws Exception {
    	this.base = base;
    }
    
    public void run() {
    	try { 
	    	for( int i = 0; i < iterations; i++ ) {
	    		StatefulKnowledgeSession session =
base.newStatefulKnowledgeSession();
	   			for( int j = 0; j < numberFacts; j++ ) {
	   				Message msg = new Message();
	   				msg.setMessage("Hello world");
	   				msg.setStatus(Message.HELLO);
	   				session.insert(msg);
	   			}
	   			session.fireAllRules();
   	   			session.dispose();
			}
		    System.out.println("Thread finished " +
this.currentThread().getName());
    	} catch( Exception e ) {
    		e.printStackTrace();
    	}
    }
}

--
View this message in context: http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p3412305.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list