[rules-users] endless loop even with "no-loop"

Gabor Szokoli szocske at gmail.com
Wed Mar 23 08:16:01 EDT 2011


This is I think something all of us came across while learning Drools...

So I searched for "drools loop faq" in google but nothing useful came up.
I propose to extend the "inifinite recursion" section in the faq with
the best practices for avoiding this!

My favorite way to avoid unnecessary activations is to include the
consequence among the conditions, negated:

rule
 when
   $object:Type(attribute!="value")
 then
  modify ($object) { setAttribute("value")}
end


Gabor

On Wed, Mar 23, 2011 at 12:30 PM, James Gu <jxgu at cnsh.delphi-tech.com> wrote:
> Hi, I am working on rule and found that it is very easy to cause endless
> loop.
>
> For example:
> Rule 1 match status and update message.
> Rule 2 match type and update message.
> This will cause endless loop even I add "no-loop" on each rule. Is there
> anyway to avoid this? for example: each rule only execute one time, or set a
> maximum execute times.
>
>
> rule "rule 1"
> no-loop
>        when
>                m : Message( status == Message.HELLO)
>        then
>                System.out.println( "rule 1" );
>                m.setMessage( "update 1" );
>                update( m );
>
> end
>
> rule "rule 2"
> no-loop
>        when
>                m:Message( type=="type1" )
>        then
>                System.out.println( "rule 2" );
>                m.setMessage( "update 2" );
>                update( m );
> end
>
> --
> View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/endless-loop-even-with-no-loop-tp2719917p2719917.html
> Sent from the Drools - User mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>




More information about the rules-users mailing list