Hello all,
I have a question about thread safety and some objects I'm developing.
Lets say for example that I've got 3 objects: user.cfc, userDAO.cfc,
userGateway.cfc. My user.cfc acts as a bean, only populated with data
from my userDAO object. The DAO object has basic querys to the db based
on a user_id. It has code something like this:
<cffunction name="read" access="public" output="false"
returntype="user">
<cfargument name="userID" type="numeric" required="yes">
<!--- lock for thread safety --->
<cflock type="exclusive" timeout="120" name="readuser">
<cfquery name="readuser" datasource="#variables.dsn#">
-- query user
</cfquery>
</cflock>
<cfif readuser.recordcount eq 1>
<cfset user = createObject("component",
"user").init(data)>
<cfelse>
<cfset user = createObject("component", "user").init()>
</cfif>
<cfreturn user>
</cffunction>
The gateway object has code similar to the following:
<cffunction name="getUser">
<cfargument name="user_id">
<!--- should this read operation be locked? --->
<cfreturn variables.userDAO.read(arguments.user_id)>
</cffunction>
If I put the gateway object into the application scope, I know that I'll
have to lock the query to get the user data from the userDAO, but is
there going to be any issues with thread safety from the userGateway
object when calling the getUser function?
Rich Kroll
Application Developer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:239074
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54