<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.hoenzb
        {mso-style-name:hoenzb;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">The simplist solution is just to change your condition to be $a : Applicant(age &lt; 18, valid != false)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Thomas<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org]
<b>On Behalf Of </b>Esteban Aliverti<br>
<b>Sent:</b> 20 January 2012 14:20<br>
<b>To:</b> Rules Users List<br>
<b>Subject:</b> Re: [rules-users] Infinit loop in simple example<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">import spikes.Applicant<br>
rule &quot;Is of valid age&quot; when<br>
&nbsp; &nbsp;$a : Applicant( age &lt; 18 )<br>
then<br>
&nbsp; &nbsp;modify( $a ) { valid = false };<br>
end<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#222222">By using modify() you are telling the engine that $a was modified in some way. This causes the re-evaluation of your rule, and since $a.age is still &lt; 18, then the rule is activated
 and fired infinite times.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#222222">Read the documentation manual about some attributes you can use in your rules to avoid this behavior: no-loop, lock-on-active.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#222222">Best Regards,<br clear="all">
</span><br>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
<br>
Esteban Aliverti<br>
- Developer @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com
</a><br>
- Blog @ <a href="http://ilesteban.wordpress.com" target="_blank">http://ilesteban.wordpress.com</a><br>
<br>
<o:p></o:p></p>
<div>
<p class="MsoNormal">On Fri, Jan 20, 2012 at 3:12 PM, roland.kofler &lt;<a href="mailto:roland.kofler@gmail.com">roland.kofler@gmail.com</a>&gt; wrote:<o:p></o:p></p>
<p class="MsoNormal">Simple example loops ad infinitum if executed:<br>
<br>
package spikes;<br>
<br>
import org.springframework.roo.addon.javabean.RooJavaBean;<br>
<br>
@RooJavaBean<br>
public class Applicant {<br>
private final String string;<br>
private final int age;<br>
public boolean valid=true;<br>
<br>
public Applicant(String string, int i) {<br>
&nbsp; &nbsp;this.string = string;<br>
&nbsp; &nbsp;this.age = i;<br>
}<br>
}<br>
DroolsSpikeTest<br>
<br>
package spikes;<br>
<br>
import static org.junit.Assert.*;<br>
<br>
import org.drools.KnowledgeBase;<br>
import org.drools.runtime.StatelessKnowledgeSession;<br>
import org.junit.Test;<br>
import org.junit.runner.RunWith;<br>
import org.springframework.beans.factory.annotation.Autowired;<br>
import org.springframework.test.context.ContextConfiguration;<br>
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;<br>
<br>
@RunWith(SpringJUnit4ClassRunner.class)<br>
@ContextConfiguration(locations={&quot;classpath:**/applicationContext-drools.xml&quot;})<br>
public class DroolsSpikeTest {<br>
<br>
&nbsp; &nbsp;@Autowired<br>
&nbsp; &nbsp;private KnowledgeBase kbase;<br>
<br>
&nbsp; &nbsp;@Test<br>
&nbsp; &nbsp;public void testspikeDroolRule() {<br>
&nbsp; &nbsp; &nbsp; &nbsp;StatelessKnowledgeSession ksession =<br>
kbase.newStatelessKnowledgeSession();<br>
&nbsp; &nbsp; &nbsp; &nbsp;Applicant a = new Applicant(&quot;Mr John Smith&quot;, 16);<br>
&nbsp; &nbsp; &nbsp; &nbsp;assertTrue(a.isValid());<br>
&nbsp; &nbsp; &nbsp; &nbsp;ksession.execute(a);<br>
&nbsp; &nbsp; &nbsp; &nbsp;assertFalse(a.isValid());<br>
&nbsp; &nbsp;}<br>
<br>
}<br>
applicationContext-drools.xml<br>
<br>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;<br>
<br>
&lt;beans xmlns=&quot;<a href="http://www.springframework.org/schema/beans" target="_blank">http://www.springframework.org/schema/beans</a>&quot;<br>
xmlns:aop=&quot;<a href="http://www.springframework.org/schema/aop" target="_blank">http://www.springframework.org/schema/aop</a>&quot;<br>
xmlns:context=&quot;<a href="http://www.springframework.org/schema/context" target="_blank">http://www.springframework.org/schema/context</a>&quot;<br>
xmlns:jee=&quot;<a href="http://www.springframework.org/schema/jee" target="_blank">http://www.springframework.org/schema/jee</a>&quot;<br>
xmlns:tx=&quot;<a href="http://www.springframework.org/schema/tx" target="_blank">http://www.springframework.org/schema/tx</a>&quot;<br>
xmlns:xsi=&quot;<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>&quot;<br>
xmlns:drools=&quot;<a href="http://drools.org/schema/drools-spring" target="_blank">http://drools.org/schema/drools-spring</a>&quot;<br>
xsi:schemaLocation=&quot;<a href="http://www.springframework.org/schema/aop" target="_blank">http://www.springframework.org/schema/aop</a><br>
<a href="http://www.springframework.org/schema/aop/spring-aop-3.1.xsd" target="_blank">http://www.springframework.org/schema/aop/spring-aop-3.1.xsd</a><br>
<a href="http://www.springframework.org/schema/beans" target="_blank">http://www.springframework.org/schema/beans</a><br>
<a href="http://www.springframework.org/schema/beans/spring-beans-3.1.xsd" target="_blank">http://www.springframework.org/schema/beans/spring-beans-3.1.xsd</a><br>
<a href="http://www.springframework.org/schema/context" target="_blank">http://www.springframework.org/schema/context</a><br>
<a href="http://www.springframework.org/schema/context/spring-context-3.1.xsd" target="_blank">http://www.springframework.org/schema/context/spring-context-3.1.xsd</a><br>
<a href="http://www.springframework.org/schema/jee" target="_blank">http://www.springframework.org/schema/jee</a><br>
<a href="http://www.springframework.org/schema/jee/spring-jee-3.1.xsd" target="_blank">http://www.springframework.org/schema/jee/spring-jee-3.1.xsd</a><br>
<a href="http://www.springframework.org/schema/tx" target="_blank">http://www.springframework.org/schema/tx</a><br>
<a href="http://www.springframework.org/schema/tx/spring-tx-3.1.xsd" target="_blank">http://www.springframework.org/schema/tx/spring-tx-3.1.xsd</a><br>
<a href="http://drools.org/schema/drools-spring" target="_blank">http://drools.org/schema/drools-spring</a><br>
<a href="http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-container/drools-spring/src/main/resources/org/drools/container/spring/drools-spring-1.0.0.xsd" target="_blank">http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-container/drools-spring/src/main/resources/org/drools/container/spring/drools-spring-1.0.0.xsd</a>&quot;&gt;<br>
<br>
&lt;drools:kbase id=&quot;kbase1&quot;&gt;<br>
&nbsp; &lt;drools:resources&gt;<br>
&nbsp; &nbsp;&lt;drools:resource id=&quot;licenseRule&quot; type=&quot;DRL&quot;<br>
source=&quot;classpath:spikes/licenseApplication.drl&quot;/&gt;<br>
&nbsp; &lt;/drools:resources&gt;<br>
&nbsp; &lt;drools:configuration&gt;<br>
&nbsp; &nbsp; &nbsp; &lt;drools:mbeans enabled=&quot;true&quot; /&gt;<br>
&nbsp; &lt;/drools:configuration&gt;<br>
&lt;/drools:kbase&gt;<br>
&lt;drools:ksession kbase=&quot;kbase1&quot; type=&quot;stateless&quot; id=&quot;ksessionStateless&quot;<br>
name=&quot;stateless1&quot; &gt;<br>
&lt;/drools:ksession&gt;<br>
&lt;/beans&gt;<br>
<br>
licenseApplication.drl<br>
<br>
import spikes.Applicant<br>
rule &quot;Is of valid age&quot; when<br>
&nbsp; &nbsp;$a : Applicant( age &lt; 18 )<br>
then<br>
&nbsp; &nbsp;modify( $a ) { valid = false };<br>
end<br>
<span style="color:#888888"><br>
<span class="hoenzb">--</span><br>
<span class="hoenzb">View this message in context: <a href="http://drools.46999.n3.nabble.com/Infinit-loop-in-simple-example-tp3675536p3675536.html" target="_blank">
http://drools.46999.n3.nabble.com/Infinit-loop-in-simple-example-tp3675536p3675536.html</a></span><br>
<span class="hoenzb">Sent from the Drools: User forum mailing list archive at Nabble.com.</span><br>
<span class="hoenzb">_______________________________________________</span><br>
<span class="hoenzb">rules-users mailing list</span><br>
<span class="hoenzb"><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a></span><br>
<span class="hoenzb"><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a></span></span><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</div>
</div>
<br>
<hr>
<font face="Arial" color="Gray" size="1"><br>
**************************************************************************************<br>
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data
 may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.<br>
<br>
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00<br>
**************************************************************************************<br>
</font>
</body>
</html>