[rules-dev] Multi threading usage best practice

9Lives 9Lives ninelives35 at hotmail.com
Mon Jul 14 08:41:00 EDT 2008


Hello
 
I'm using Drools 4.0.7 inside a mail relay application 2 determine the operations that need 2 b executed on each passing message.
To do this i'm using the following scenario:


I have a ruleBase.newStatefulSession().

I have a fixed set of facts.

I have a fixed set of rules.

Each mailer (a thread that is handling a single message) is inserting the message to the working memory, calls the "fireAllRules" method and retracts the message.

Rules that r executed change custom attributes in the message.
Problem:
I noticed that sometimes a rule can b executed on the same message more then once.
 
Assumption:
My guess is that because i'm working is a multi threading environment but using a stateful session, what happens is:

Thread A is inserting Message A.
Thread B is inserting Message B
Thread A is calling fireAllRules
Rule X is executed on messages A + B.
Thread B is calling fireAllRules
Rule X is executed on messages A + B
Thread A is retracting Message A
Thread B is retracting message B
Question:
My goal is 2 make sure a rule is executed only once on a single message.
Any ideas on how 2 avoid the situation described above?
 
TnX
Dotan
 
 
_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20080714/e1e9a226/attachment.html 


More information about the rules-dev mailing list