say I have the following drools rule in drl
global java.lang.Boolean test;
rule "Initialize global"
salience 1000
when
then drools.workingmemory.setGlobal("test", new Boolean(true))
end
This works as expected but I also don’t want the rule to fire everytime so I want to add the checking if the global test has been initialized or not, if not, then set it, otherwise, dont fire the rule. How would you do this?
I believe I also need no-loop true for this.
Thanks for your help
Using a rules without constraints is a common pattern for initialization rules. The rule you have is only executed once per session, so don’t worry about re-execution.
About no-loop, since you don’t have any condition in your rule, it can’t be reactivated. No-loop is used to avoid recursive activations when you are using modify() or update() in the RHS.
Best regards’