Search code examples
droolsjbpm

drools stateless vs stateful session


When should I use Drools stateless session and what are the benefits of using it instead of stateful session?
In some comment here it's said that stateless sessions wraps a stateful one, does it means that when I destory the statfeul session after firing all rules would behave like a stateful one ?


Solution

  • Perhaps it would be better to say that both (stateful) KieSession and StatelessKieSessions provide APIs (interfaces) to classes based on class AbstractRuntime.

    A StatelessKieSession provides an interface for executing a set of commands via a single execute method call, commands being represented as a set of objects. This is useful if you want to send commands to a remote session (but not if you run the session within your application). Also, such a session will not react to changes done within Working Memory, so its usefulness is limited, although it might perform the first and only round more efficient than a stateful session.

    An execute call implies a dispose call, which is the final goodbye to the session object: release all resources into garbage collection.

    To summarize (what is described in full in the Drools documentation)

    • For simple rule evaluations, especially via some remote communication, use a stateless session.
    • To make use of the full power of a Production System, i.e., the continued reevaluation of rule conditions as a consequence of altered facts and changed fact lineups, it is necessary to use a stateful session.

    Don't worry about "benefits" if you are planning for a simple application interface: just use a stateful session.