[rules-users] Executing more than one rules having no infinite execution

Esteban Aliverti esteban.aliverti at gmail.com
Fri Dec 7 03:12:23 EST 2012


Using drools.halt() is not considered a good practice at all. I would
recommend you to read this post:
http://ilesteban.wordpress.com/2012/11/16/about-drools-and-infinite-execution-loops/

Best Regards,


XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Blog @ http://ilesteban.wordpress.com



On Fri, Dec 7, 2012 at 8:59 AM, Hushen Savani
<hushen.savani at elitecore.com>wrote:

>  Hi,****
>
> ** **
>
>                 I have a simple rule as following:****
>
> ** **
>
> *import java.util.HashMap;*
>
> * *
>
> *rule "first"*
>
> *when*
>
> *     a : CrestelRuleModel( $hmap : singleHashMap!=null);*
>
> *then*
>
> *     System.out.println("Old Map: " + $hmap);*
>
> *     HashMap mapp = new HashMap();*
>
> *     mapp.put("hello", "world");*
>
> *     a.setSingleHashMap(mapp);*
>
> *     System.out.println("New Map: " + a.getSingleHashMap());*
>
> *     update(a);*
>
> *end;*
>
> ** **
>
> When I invoke the rule from my client, the rule is executed *infinitely*.*
> ***
>
> ** **
>
> So, I have placed a “*drools.halt()*” before “*end*” statement of above
> rule. So, it stopped executing infinitely as I wanted. But *is it a good
> practice?*****
>
> ** **
>
> Now, I want my input to be filtered by *two rules*, so I have placed
> rules like following:****
>
> ** **
>
> *import java.util.HashMap;*
>
> * *
>
> *rule "first"*
>
> *when*
>
> *     a : CrestelRuleModel( $hmap : singleHashMap!=null);*
>
> *then*
>
> *     System.out.println("Old Map: " + $hmap);*
>
> *     HashMap mapp = new HashMap();*
>
> *     mapp.put("hello", "world");*
>
> *     a.setSingleHashMap(mapp);*
>
> *     System.out.println("New Map: " + a.getSingleHashMap());*
>
> *     update(a);*
>
> *     drools.halt();*
>
> *end;*
>
> * *
>
> *rule "second"*
>
> *when*
>
> *     b : CrestelRuleModel( $hmap2 : singleHashMap!=null);*
>
> *then*
>
> *     System.out.println("Old Map2: " + $hmap2);*
>
> *     HashMap mapp2 = new HashMap();*
>
> *     mapp2.put("hello2", "world2");*
>
> *     b.setSingleHashMap(mapp2);*
>
> *     System.out.println("New Map2: " + b.getSingleHashMap());*
>
> *     update(b);*
>
> *     drools.halt();*
>
> *end;*
>
> ** **
>
> But in above case, *only the “second”  rule executes*. What to do in
> order to execute both the rules without any infinite loop?****
>
> ** **
>
> Kindly share some pointers on this. Thanks.****
>
> ** **
>
> ** **
>
> *PS*: *CrestelRuleModel* is my POJO model having following fields,****
>
> * *
>
> *public* *class* CrestelRuleModel {****
>
>        ****
>
>        *private* *ArrayList* arrayListOfHashMap;****
>
>        *private* *HashMap* singleHashMap;****
>
>        *private* Object object;****
>
>        *private* String remarks;****
>
> ** **
>
>        //Getters and Setters****
>
> ** **
>
> }****
>
> ** **
>
> Best Regards****
>
> *Hushen Savani* | Crestel Billing****
>
> [image: ecTag]****
>
> ** **
>
> _______________________________________________
> 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/20121207/9f029c9a/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 2753 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20121207/9f029c9a/attachment.png 


More information about the rules-users mailing list