0

In the below rules I expect Rule2 is fire because I am modifying customer name to mahesh. But when I execute Rule2 is not firing but Rule3 is firing. Am I missing anything here

  rule "Rule1"
lock-on-active true
salience 95
    when
        $c:Customer($customerName:customerName)
    then
    System.out.println($customerName+" =======2========");
    modify($c){
            setCustomerName("mahesh");
        }
        System.out.println($customerName);
end

rule "Rule2"
lock-on-active true
salience 85 
    when
        $c1:Customer($customerName:customerName=="mahesh");
    then
        System.out.println($customerName+" Rules Name is 1 - " + drools.getRule().getName());
         $c1.setCustomerName("mahesh456");
        update($c1);
end

rule "Rule3"
lock-on-active true
    when
        $c:Customer($customerName:customerName)
    then
        System.out.println($customerName+ "***** ");
end 
Ganesh
  • 167
  • 1
  • 7
  • 21
  • I removed lock-on-active true, Then Rule2 is fired, But did not get how adding lock-on-active true, makes rule2 not to fire!! – Ganesh Jul 04 '18 at 18:21

1 Answers1

0

What lock-on-active does is to prevent a rule to be activated if the agenda group where the rule is defined is already active. In your case, because you was already executing the rules (fireAllRules) the MAIN agenda group (which is the group that both of your rules belong to) was already active. This mean that the second rule activation is going to be cancelled by Drools.

You can find here a more in depth explanation.

Hope it helps,

Esteban Aliverti
  • 6,259
  • 2
  • 19
  • 31