[rules-users] StatefulKnowledgeSession.dispose()

Swindells, Thomas TSwindells at nds.com
Fri Oct 21 06:05:45 EDT 2011


You only need to dispose of the session when you no longer want the session.
It's perfectly valid to keep reusing the session as long as you want, inserting,
removing and calling fire all rules as many times as you want. If you do reuse
the session you just need to be careful that previous iterations of the loop don't
have undesirable results on subsequent executions - eg if your rules insert control
facts and you don't tidy them up.

So in the code below you should just move the dispose outside the loop after you
have done all the iterations.

Thomas
> -----Original Message-----
> From: rules-users-bounces at lists.jboss.org [mailto:rules-users-
> bounces at lists.jboss.org] On Behalf Of tonytang
> Sent: 21 October 2011 10:55
> To: rules-users at lists.jboss.org
> Subject: Re: [rules-users] StatefulKnowledgeSession.dispose()
>
> B.T.W I use Drools 5.2 to test
> Hi,

I have a quesion about StatefulKnowledgeSession.dispose().
Can continue to use the session instance ofter call dispose() method.

I write a test code to test it and it is works fine.
and it is almot 10 time fast than not call dispose().  Why???

But When I use Jboss Enterprise BRMS to run this test case.
It is throw a NullPointException when call dispose() at the second time.

Why????

for (int i = 0; i < 100; i++) {
FactHandle handle = session.insert(messageList.get(i));//
session.fireAllRules();

session.retract(handle);

session.dispose();
}
>



**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster at nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************




More information about the rules-users mailing list