简体   繁体   中英

how drools endless loop in one rule?

I use drools to do some logic, the DRL is like that. My question is like that when I add "rules:Rules()", the loop will loop in "young" first until age larger than 19, but if I remove "rules:Rules()", it will only do once in young. Can someone tell me why?

rule "young"
when
   rules:Rules() 
   person:Person(Person.age< 19) 
then
    person.age+=1
    System.out.println("young"); 
end

rule "adult"
when
   rules:Rules() 
   person:Person(Person.age>= 19) 
then
    person.age+=1
    System.out.println("adult"); 
end

You should use modify to let Drools know you are changing the state of the person .

rule "young-without-rules"
when
   $person: Person(age < 19) 
then
    modify ($person) {
       age = age+1
    }
    System.out.println("young"); 
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM