Drools:stateless vs stateful knowledge session

tech2504 picture tech2504 · Jun 18, 2013 · Viewed 27.4k times · Source

What is difference between stateless and stateful knowledge sessions.I read some documents both are maintained state.But when can i use stateless/stateful knowledge sessions.

Answer

Prakhyat picture Prakhyat · Jun 26, 2013

Stateless: The facts/working memory is inserted to Knowledge base session before firing rules. These facts can be set by calling public methods on an object while executing rules and after setting these objects are returned back with changed values.

Any changes in the facts while executing rules, for example insert(xyz) or modify(xyz), is not made aware to the rule engine.

Stateful: The facts/working memory is inserted to Knowledge base session before firing rules and after the rules are fired dispose() has to be called to avoid memory leaks.

Any changes in the facts while executing rules, for example insert(xyz) or modify(xyz), is made aware to the rule engine.