如何在地图中的 Drools 规则之间共享数据?

发布于 2024-12-18 22:31:30 字数 238 浏览 5 评论 0原文

我有一条规则,它接受 Map() 作为事实,然后为此地图设置大量元素。我希望在执行其他规则时能够在其他地方使用此映射。我在 Drools 中读到了有关全局变量的信息,但似乎它们不应该用于此目的。现在,我将此映射保留为 Java 类中的私有属性,以便它可以将所有数据保留在 Web 应用程序上下文中,但这会增加我的内存占用。我知道这可能听起来很奇怪,但是 Drools 规则与 Java 静态字段有什么类比吗?

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动次打次papapa 2024-12-25 22:31:30

您能否进一步解释一下您的规则试图实现的目标是什么?大多数时候,您应该重新制定规则以满足您的需求。过滤 Map() 的规则需要将 java.util.Map 的实例插入到知识会话中。如果您将 Map 添加为全局,您的规则将无法直接过滤 Map()。我通常建议使用更结构化的事实/对象来编写规则,而不是通用结构。
请记住,如果将 java.util.Map 实例插入到会话中,则该 Map 将可用于过滤 Map() 对象类型的所有规则。

希望它对您有所帮助,如果您可以提供更多信息,我们将能够为您提供进一步的帮助。

干杯

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文