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

Anderson Neves anderson.ufal at gmail.com
Wed Mar 23 08:29:21 EDT 2011


Hi.

I like to add negated attributes in the condition, or other attributes that
better describe the object state, like below. If you write two rules to the
same object state, you should think to join the rules into one rule.

rule
 when
    $object:Type(attribute=="value", secondAttribute == false,
thirdAttribute == "")
 then
    // do consequence
end

Regards,
Anderson

2011/3/23 Gabor Szokoli <szocske at gmail.com>

> 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
> >
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110323/c46dc40c/attachment.html 


More information about the rules-users mailing list