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

Juan Carlos Fernández juancarlos.fernandez at safelayer.com
Tue Oct 11 09:13:22 EDT 2011


Same result. This is the source code.

This test tells us that insert() locks too (too many internal resize and
system memory operations).

I tested passing to thread class the session, the knowledge base and create
session at thread construction time, at thread execution time. I obtain the
same result for all tests.

Oh, yes, if I insert "double a = Math.sqrt(1919) * Math.sqrt(1919);" in the
thread execution without drools code, I can see 100% CPU usage :-)

The only solution that increases CPU usage is the pooling one.

Oh my god!

public class KnowledgeSessionThread extends Thread { 
    
    private static final int iterations = 500; 
    private static final int numberFacts = 1000; 
    private StatefulKnowledgeSession session; 
    
	public KnowledgeSessionThread(StatefulKnowledgeSession sess) throws
Exception { 
		this.session = sess; 
	} 

	public void run() { 
		try { 
			for( int i = 0; i < iterations; i++ ) { 
				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-tp3412107p3412530.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list