How does update function works in drools?

烈酒焚心 提交于 2019-12-30 10:45:19

问题


How does update function works in drools? Does it cause the same rules fire again automatically?


回答1:


I think you need to read the manual: http://docs.jboss.org/drools/release/5.4.0.Final/drools-expert-docs/html_single/

Using update makes the rules engine aware that a fact has been modified. Therefore rules which depend upon that fact must be re-evaluated. This does have the effect that a rule may fire in an endless cycle. For instance, given the following DRL, you will see that the "Infinite loop" rule will activate continuously:

declare AreWeThereYet
    answer : boolean
end

rule "Are we there yet?"
when
    not AreWeThereYet()
then
    insert(new AreWeThereYet());
end

rule "Infinite loop"
    no-loop
when
    $question: AreWeThereYet()
then
    $question.setAnswer(false);
    update($question);
end

This is because the rules engine has been instructed by update($question), that $question has changed and that it needs to re-evaluate it.

There are ways of preventing this though. Just put no-loop on the line between the rule name and when to prevent rules from re-activating as a result of their own consequences. Another rule attribute which can control this is lock-on-active.



来源:https://stackoverflow.com/questions/14507633/how-does-update-function-works-in-drools

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