How to share data between Drools rules in a map?

自古美人都是妖i 提交于 2019-12-11 16:17:30

问题


I have a rule which accepts Map() as a fact and then sets lots of elements to this map. I want to be able to use this map somewhere else when executing other rules. I read about globals in Drools but seems like they should not be used for this purpose. Right now I keep this map as private property in Java class, so that it can keep all data in web application context, but this increases my memory footprint. I know it might sound bizarre but is there any analogy in Drools rules to Java static fields?

Thanks in advance!


回答1:


can you explain a little bit more about what is your rule trying to achieve? most of the times you should reformulate the rules in order to fit your needs. A rule that filters a Map() require an instance of java.util.Map to be inserted inside the knowledge session. If you add a Map as a global your rules will not be able to directly filter a Map(). I usually recommend to use more structured facts/objects to write rules instead of generic structures. Remember that if you insert a java.util.Map instance to the session, that Map will be available for all the rules that filters the Map() object type.

Hope it helps, if you can provide more information we will be able to help further.

Cheers



来源:https://stackoverflow.com/questions/8353997/how-to-share-data-between-drools-rules-in-a-map

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