In the exploration of finding out when to use stateful or stateless session in Drools, the next information is very useful:
- Drools:stateless vs stateful knowledge session
- Stateless Vs Stateful Session behavior in drools
- drools stateless vs stateful session
It seems clear when to use stateless vs stateful session.
But I became somewhat confused because of the following information here:
In that link people discuss switching from stateful session to stateless session. Gathering all information, I conclude that it seems possible to switch a stateful session to a stateless session, to avoid possible memory problems (?), by:
- Adding facts into a List
- Add the List to the stateless session with the execute command (or either add it to a global).
- Obtain the different facts in the rules with a query
- Add results to a global variable or variables to be able to obtain the results from the stateless session
Which seems like bad practices to me, only to avoid the use of a stateful session.
My questions are:
- Is my previous conclusion correct?
- Why would I want to switch from stateful sessions to stateless sessions? Is there a memory problem in KIE and when do these occur?
- I think the real difference between stateless and stateful sessions comes to the fact whether I just validate (in stateless session) data or add value (in stateful session) to data. That would be a design issue, not a technical issue. Is that correct?