drools stateless vs stateful session

最后都变了- 提交于 2019-12-11 09:48:30

问题


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 ?


回答1:


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.




回答2:


If you want to update or want to have control over the facts(data) passed to the rule during rule execution use stateful session. You can use modify,retract methods.

If you don't want to update the facts during rule exection, use stateless session.



来源:https://stackoverflow.com/questions/33463155/drools-stateless-vs-stateful-session

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!