Ste*_*eve 14
我想你需要阅读手册:http://docs.jboss.org/drools/release/5.4.0.Final/drools-expert-docs/html_single/
使用update使规则引擎意识到事实已被修改.因此,必须重新评估依赖于该事实的规则.这确实会导致规则在无休止的循环中发射.例如,给定以下DRL,您将看到"无限循环"规则将持续激活:
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
Run Code Online (Sandbox Code Playgroud)
这是因为规则引擎已经被指示update($question),$question已经改变并且需要重新评估它.
但是有办法防止这种情况发生.只需no-loop在规则名称之间加上一条线就when可以防止规则因自身后果而重新激活.另一个可以控制它的规则属性是lock-on-active.