[rules-users] Reuse statless session

Bruno Freudensprung bruno.freudensprung at temis.com
Wed Oct 27 03:47:28 EDT 2010


Alright... The test case was delivered with the following documentation 
(extract of the "Drools JBoss Rules 5.0 Developer's Guide" book):

"org.drools.runtime.StatelessKnowledgeSession
This is a type of knowledge session that doesn't keep any state between 
invocations (an invocation is a call of the execute method). From the 
rules perspective, a stateless session is no different than a stateful 
session---the rules look exactly the same. The benefit that 
statelessness brings is that the rule engine can do more optimizations. 
StatelessKnowledgeSession as well as stateful session support a command 
interface (command design pattern). There is no need to dispose a 
stateless session after it has been used."

Bruno.

Patrick van Kann a écrit :
> I might be putting too simplistic an interpretation on this, but this 
> is what the Javadoc says for StatelessKnowledgeSession
>
> "StatelessKnowledgeSession provides a convenience API, wrapping 
> StatefulKnowledgeSession. It avoids the need to call dispose(). 
> Stateless sessions do not support iterative insertions and 
> fireAllRules from Java code, the act of calling execute(...) is a 
> single shot method that will internally instantiate a 
> StatefulKnowledgeSession, add all the user data and execute user 
> commands, call fireAllRules, and then call dispose()."
>
> So I'm not sure why you just wouldn't just directly use a 
> StatefulKnowledgeSession instead of trying to re-use a stateless one. 
> You can then update the Facts via their handles and update or retract 
> and reinsert as needed.
>
> Cheers,
>
> Pat
>
> On Tue, Oct 26, 2010 at 3:50 PM, Bruno Freudensprung 
> <bruno.freudensprung at temis.com <mailto:bruno.freudensprung at temis.com>> 
> wrote:
>
>
>     Hi,
>
>     According to what I've read so far, you can reuse Stateless sessions.
>     In particlar I've seen unit tests creating a Stateless session in a
>     @BeforeClass method, then this session was re-used across multiple
>     tests
>     methods "pushing" different data-sets into that unique session
>     instance
>     using commands (created with the org.drools.command.CommandFactory
>     class).
>
>     Regards,
>
>     Bruno.
>
>     espen a écrit :
>     > Hi,
>     >
>     > we have an application with a lot of rules in a cached rulebase.
>     When we
>     > profile our application we see that about 30% of the time is used in
>     > rulebase.newStatlessSession(). The time is basically used
>     loading classes.
>     >
>     > The question is, is it possible to create a pool of
>     StalessSessions and
>     > reuse them, or will this create problems.
>     >
>     > Regards
>     > Espen
>     >
>
>     _______________________________________________
>     rules-users mailing list
>     rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
>     https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101027/0fdabc9f/attachment.html 


More information about the rules-users mailing list