Drools:stateless vs stateful knowledge session

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.


Stateless means a new session is created for each request (so no state is maintained). Stateful means it will continue from whatever state the session was when the previous command ended (for example, all data that was inserted into the session will still be there).


The basic difference the way i see it, is the way the session is auto disposed in stateless. There are no performance gain to be had by choosing one vs. other. Actually, the stateless session uses a stateful session behind it. So go figure!

Tags:

Drools