Drools Stateful vs Stateless Knowledge Session - Java @ Desk

Tuesday, June 17, 2014

Drools Stateful vs Stateless Knowledge Session

Drools Stateful vs Stateless Knowledge Session

Knowledge Session in Drools is the core component to fire the rules. Its the knowledge session that holds all the rules and other recources.

Knowledge Session is created from the KnowledgeBase which includes all the rules.

Knowledge Session in Drools is of 2 types :
1) Stateful Knowledge Session
2) Stateless Knowledge Session

Difference between the 2 :

1) In case of Stateless Knowledge Session, while rules execution i.e. once fireRules method is called, and modification in the inserted facts (in the then part) is not available to the rules engine. In case of Stateful Knowledge Session, any changes in the facts is available to the rule engine.

2) Once rules are fired, Stateful Knowledge Session object must call the method dispose() to release the session and avoid memory leaks.

3) In case of Stateful Knowledge Session, any changes to facts is available to the rule engine. So the rules are called iteratively. If Fact A is modified in last rule of DRL, then this change will re-activate all the rules and fire the rules that are build on Fact A. This is not the case with Stateless Knowledge Session.

The hidden fact is Stateless session uses a Stateful session behind it







No comments:

Post a Comment