<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>Opsss. Sorry ... my mistake<BR>
&nbsp;<BR>
The phrase: <BR>
"I did use sync on any reference ..." <BR>
should b:<BR>
"I did <STRONG>not</STRONG> use sync on any reference ..."<BR><BR>Dotan<BR><BR><BR>

<HR id=EC_stopSpelling>
<BR>
From: ninelives35@hotmail.com<BR>To: rules-dev@lists.jboss.org<BR>Subject: RE: [rules-dev] Multi threading usage best practice<BR>Date: Mon, 14 Jul 2008 17:53:59 +0300<BR><BR>
<META content="Microsoft SafeHTML" name=Generator>
<STYLE>
.ExternalClass .EC_hmmessage P
{padding:0px;}
.ExternalClass body.EC_hmmessage
{font-size:10pt;font-family:Tahoma;}
</STYLE>
I did use sync on any reference 2 the working memory with the hope of archiving the maximum performance from Drools.<BR>Stateless session seems like a waste of resources when thinking of the volume of messages passing through the server and translating that 2 create and destroy a session per each one.<BR><BR>MayB i should rephrase my rules in some way that they would know if the message was already processed?<BR>&nbsp;<BR>Dotan<BR><BR><BR>

<HR id=EC_EC_stopSpelling>
<BR>
<BR>Subject: RE: [rules-dev] Multi threading usage best practice<BR>Date: Mon, 14 Jul 2008 14:51:49 +0100<BR>From: manstis1@ford.com<BR>To: rules-dev@lists.jboss.org<BR><BR><BR><BR>
<STYLE>
.ExternalClass .EC_hmmessage P
{padding-right:0px;padding-left:0px;padding-bottom:0px;padding-top:0px;}
.ExternalClass BODY.EC_hmmessage
{font-size:10pt;font-family:Tahoma;}
</STYLE>

<DIV dir=ltr align=left><SPAN class=EC_EC_030514513-14072008><FONT face=Arial color=#0000ff>Did you synchronise on the insertion of objects into working memory too? (not as part of an activation on the RHS).</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=EC_EC_030514513-14072008><FONT face=Arial color=#0000ff></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=EC_EC_030514513-14072008><FONT face=Arial color=#0000ff>What about the use of a stateless session per thread (isn't session creation really quick once the package\rulebase has been compiled)? </FONT></SPAN><FONT face=Arial><FONT color=#0000ff>I<SPAN class=EC_EC_030514513-14072008>n the mail relay below won't you want the set of rules to apply to one set of facts inserted by one thread representing one message? Is this achievable with a shared working memory? (Could you not get an activation caused by the presence of a fact inserted into working memory by one thread and the insertion into the same working memory of a fact by another thread).</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><SPAN class=EC_EC_030514513-14072008></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><SPAN class=EC_EC_030514513-14072008>This is much more interesting that work ;-)</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><SPAN class=EC_EC_030514513-14072008></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><SPAN class=EC_EC_030514513-14072008>Mike</SPAN></FONT></FONT></DIV>
<DIV dir=ltr align=left><BR></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=EC_EC_OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR>
<FONT face=Tahoma><B>From:</B> rules-dev-bounces@lists.jboss.org [mailto:rules-dev-bounces@lists.jboss.org] <B>On Behalf Of </B>Fenderbosch, Eric<BR><B>Sent:</B> 14 July 2008 14:36<BR><B>To:</B> Rules Dev List<BR><B>Subject:</B> RE: [rules-dev] Multi threading usage best practice<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV dir=ltr align=left><SPAN class=EC_EC_375443413-14072008><FONT face=Arial color=#0000ff>We have multiple threads performing inserts/updates/queries/fireAllRules and had to synchronize access on working memory.&nbsp; The performance impact is surprisingly almost non-existent.</FONT></SPAN></DIV><BR>
<DIV class=EC_EC_OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR>
<FONT face=Tahoma><B>From:</B> rules-dev-bounces@lists.jboss.org [mailto:rules-dev-bounces@lists.jboss.org] <B>On Behalf Of </B>Anstis, Michael (M.)<BR><B>Sent:</B> Monday, July 14, 2008 9:24 AM<BR><B>To:</B> Rules Dev List<BR><B>Subject:</B> RE: [rules-dev] Multi threading usage best practice<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV dir=ltr align=left><SPAN class=EC_EC_055561913-14072008><FONT face=Arial color=#0000ff>Hi,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=EC_EC_055561913-14072008><FONT face=Arial color=#0000ff></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=EC_EC_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=EC_EC_055561913-14072008><FONT face="Courier New" color=#0000ff>...</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=EC_EC_055561913-14072008><FONT face="Courier New" color=#0000ff>synchronised(wm) {</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=EC_EC_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=EC_EC_055561913-14072008><FONT face="Courier New" color=#0000ff>}</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=EC_EC_055561913-14072008><FONT face="Courier New" color=#0000ff>...</FONT></SPAN></DIV></BLOCKQUOTE>
<DIV dir=ltr align=left><SPAN class=EC_EC_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=EC_EC_055561913-14072008><FONT face=Arial color=#0000ff></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=EC_EC_055561913-14072008><FONT face=Arial color=#0000ff>Cheers,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=EC_EC_055561913-14072008><FONT face=Arial color=#0000ff></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=EC_EC_055561913-14072008><FONT face=Arial color=#0000ff>Mike</FONT></SPAN></DIV><BR>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px">
<DIV class=EC_EC_OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR>
<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=_blank>Try it!</A> </BLOCKQUOTE></BLOCKQUOTE><BR>
<HR>
Connect to the next generation of MSN Messenger&nbsp; <A href="http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&amp;source=wlmailtagline" target=_blank>Get it now! </A><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&wx_url=/friends.aspx&mkt=en-us' target='_new'>Try it!</a></body>
</html>