1

In the exploration of finding out when to use stateful or stateless session in Drools, the next information is very useful:

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?
Ruurd
  • 151
  • 9
  • Don't try to be too clever. Assuming that you want to have rules evaluated with the full power of Drools: use a stateful session. – laune Jul 28 '17 at 16:40
  • Thanks for your answer. I assume that the assumption about bad practices is correct then. But I am still wondering if there is a memory issue in KIE and when that happens. Can you provide more information on that? – Ruurd Aug 02 '17 at 09:08
  • Apart from the trivial statement that memory usage depends on the number and storage requirements of inserted fact objects one cannot say very much. The node network used by the Rule Engine depends on the number and complexity of the rules. Solutions resulting in 5- or 6-digit numbers of rules may cause problems. – laune Aug 02 '17 at 09:59
  • Thank you very much, that is useful information. Unfortunately for this being commentaries I cannot indicate both your commentaries as the right answer. – Ruurd Aug 02 '17 at 11:54

0 Answers0