<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<STYLE>.hmmessage P {
        PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px
}
BODY.hmmessage {
        FONT-SIZE: 10pt; FONT-FAMILY: Tahoma
}
</STYLE>

<META content="MSHTML 6.00.2900.3314" name=GENERATOR></HEAD>
<BODY class=hmmessage>
<DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT face=Arial 
color=#0000ff>Hi,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT face=Arial 
color=#0000ff></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT face=Arial 
color=#0000ff>Would synchronising on working memory effectively serialise the 
effects of fireAllRules()?</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT 
  face="Courier New" color=#0000ff>...</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT 
  face="Courier New" color=#0000ff>synchronised(wm) {</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT 
  face="Courier New">&nbsp;&nbsp;&nbsp; <FONT 
  color=#0000ff>wm.fireAllRules();</FONT></FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT 
  face="Courier New" color=#0000ff>}</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT 
  face="Courier New" color=#0000ff>...</FONT></SPAN></DIV></BLOCKQUOTE>
<DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT face=Arial 
color=#0000ff>I don't know whether this would kill your through-put 
either.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT face=Arial 
color=#0000ff></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT face=Arial 
color=#0000ff>Cheers,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT face=Arial 
color=#0000ff></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=055561913-14072008><FONT face=Arial 
color=#0000ff>Mike</FONT></SPAN></DIV><BR>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
  <HR tabIndex=-1>
  <FONT face=Tahoma><B>From:</B> rules-dev-bounces@lists.jboss.org 
  [mailto:rules-dev-bounces@lists.jboss.org] <B>On Behalf Of </B>9Lives 
  9Lives<BR><B>Sent:</B> 14 July 2008 13:41<BR><B>To:</B> 
  rules-dev@lists.jboss.org<BR><B>Subject:</B> [rules-dev] Multi threading usage 
  best practice<BR></FONT><BR></DIV>
  <DIV></DIV>Hello<BR>&nbsp;<BR>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.<BR>To do this i'm using the following scenario:<BR>
  <OL>
    <LI>
    <DIV>I have a ruleBase.newStatefulSession().</DIV>
    <LI>
    <DIV>I have a fixed set of facts.</DIV>
    <LI>
    <DIV>I have a fixed set of rules.</DIV>
    <LI>
    <DIV>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.</DIV>
    <LI>
    <DIV>Rules that&nbsp;r executed change custom attributes in the 
    message.</DIV></LI></OL>Problem:<BR>I noticed that sometimes a rule can b 
  executed on the same message more then once.<BR>&nbsp;<BR>Assumption:<BR>My 
  guess is that because i'm working is a&nbsp;multi threading&nbsp;environment 
  but using a stateful session, what happens is:<BR>
  <OL>
    <LI>Thread A is inserting Message A. 
    <LI>Thread B is inserting Message B 
    <LI>Thread A is calling fireAllRules 
    <LI>Rule X is executed on messages A + B. 
    <LI>Thread B is calling fireAllRules 
    <LI>Rule X is executed on messages A + B 
    <LI>Thread A is retracting Message A 
    <LI>Thread B is retracting message B</LI></OL>Question:<BR>My goal is 2 make 
  sure a rule is executed only once on a single message.<BR>Any ideas on how 2 
  avoid the situation described 
  above?<BR>&nbsp;<BR>TnX<BR>Dotan<BR>&nbsp;<BR>&nbsp;<BR><BR>
  <HR>
  Invite your mail contacts to join your friends list with Windows Live Spaces. 
  It's easy! <A 
  href="http://spaces.live.com/spacesapi.aspx?wx_action=create&amp;wx_url=/friends.aspx&amp;mkt=en-us" 
  target=_new>Try it!</A> </BLOCKQUOTE></BODY></HTML>