On Saturday, Jul 26, 2003, at 16:40 US/Pacific, St�phane Bisson wrote:
<cfif NOT IsDefined("Application.ValidateService")>
 <cflock scope="Application" Timeout="10" THROWONTIMEOUT="No"
Type="Exclusive">
    <cfobject component="#request.componentpath#ValidateService"
name="Application.ValidateService">
 </cflock>
</cfif>

This is not sufficient to avoid race conditions. You need the following construct:


<cfif NOT IsDefined("Application.ValidateService")>
 <cflock scope="Application" Timeout="10" THROWONTIMEOUT="No"
Type="Exclusive">
   <cfif NOT IsDefined("Application.ValidateService")>
    <cfobject component="#request.componentpath#ValidateService"
name="Application.ValidateService">
   </cfif>
 </cflock>
</cfif>

Without the extra cfif, you could still have two threads perform the initialization.

MyCFC.cfc
...
<cflock scope="Application" Timeout="10" THROWONTIMEOUT="No"
Type="ReadOnly">
<cfset in_message = Application.ValidateService.Filter(in_message)>
</cflock>
...

You do not need to lock here as long as your CFC is only reading values. If it is setting values in application scope, you need to consider race conditions but, since you are storing the CFC in application scope it is probably stateless and therefore it is not updating state and you do not need to lock.


Is it the good way to prevent race condition! I think I heared once that I
don't need to put cflock readonly! but I don't remember why!

I hope my comments make it clear? I'd point you to the link on my blog about locking but after I upgraded my ISP, I lost a lot of the comments and links :(


Sean A Corfield -- http://www.corfield.org/blog/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev'
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

Reply via email to