Globals should only be used for data that is constant over the life of the working memory, which is not so in your case.

Maybe you should just use a fact counter. If you don't want to affect your code you could insert it in a separate rule.


On Tue, Dec 9, 2008 at 9:05 AM, techy <> wrote:

I would like to take 100 sampling facts for rule and persist it in the db
and ignore other data.
How Can I maintain the counter? as global variable? Please clarify with
sample code.
I tried following way and but it does not work as expected.

global Integer counter;
rule "get sampling data"
  when fact : Foo(some condition) && eval(counter <= 100)
  // do some condition
View this message in context:
Sent from the drools - user mailing list archive at

rules-users mailing list

Steven Williams

Supervising Consultant

Object Consulting
Office: 8615 4500 Mob: 0439 898 668 Fax: 8615 4501

consulting | development | training | support
our experience makes the difference