cf-talk  

Re: Possible thread issue?

Leigh
Tue, 08 Dec 2009 21:04:05 -0800

> It pretty much looks like a singleton design!

Yep. I think Jaime has it right. It looks like few (if any) of the variables 
set within the DAO's functions are VAR scoped. So they will automatically be 
placed in the shared "variables" scope. Since you are working with a singleton, 
those variables will be accessible to multiple threads. Under heavy load, it is 
very likely that would lead to the behavior you have described. ie One thread 
overwriting values set by another.

All variables that are local to a function must be VAR-scoped. That ensures 
they are only visible to the function, and not other threads.  It seems like 
the code starts to do the right thing by declaring the function-local structure 
"stTrans". 

<cffunction name="process" access="public" returntype="struct"> 
  .....
  <cfset var stTrans = structNew() /> 
  ....
 <!--- 
    theCurrentAvailableBalance will be place the shared variables scope
 --->

</cffunction>

But then starts using un-VAR'd variables like:

 <cfset theCurrentAvailableBalance = 
variables.accountService.getAccountBalance("available", arguments.acctid)> 
...

Since theCurrentAvailableBalance was not var-scoped (or added to an object that 
_was_ var-scoped) it will fall into the "variables" scope. Since the DAO 
functions seem to use a lot of variables, the easiest way to make them 
function-local would to add them to the localized structure "stTrans". **Note, 
as Jaime mentioned this includes query names as well.

Example:
 <cfset stTrans.theCurrentAvailableBalance = 
variables.accountService.getAccountBalance("available", arguments.acctid)> 
<cfset stTrans.theCurrentActualBalance = 
variables.accountService.getAccountBalance("actual", arguments.acctid)>  
... etcetera ...


<cfquery datasource="#variables.dsn#" name="stTrans.trans_insert" 
result="stTrans.trans_insert_res"> 
.....


HTH
-Leigh





      

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:328997
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4