CFLOCK.   I usually do something like this in Application.cfm:

<cflock scope="application" type="readonly">
  <cfset needsRefresh = NOT structKeyExists(application, app_vars_loaded) />
</cflock>

<cfif needsrefresh>
  <cflock scope="application" type="exclusive">
    <cfif NOT structKeyExists(application, app_vars_loaded)>
      <!--- do initialization --->
      <cfset application.app_vars_loaded = true />
    </cfif>
  </cflock>
</cfif>

That will assure that no request will initialize if it's already been done
(the first CFIF), no request will start initialization while another request
is in the process (the second CFLOCK), and that no request will reinitialize
the app, if it's already read (the second CFIF).

Cheers,
barneyb

> -----Original Message-----
> From: Brook Davies [mailto:[EMAIL PROTECTED]
> Sent: Thursday, February 26, 2004 11:35 AM
> To: CF-Talk
> Subject: Race conditions at start up
>
> When my CFMX server is restarted my app needs to do a lot of
> housekeeping.
> It goes out and fetches the exchange rate, it sets up some
> application vars
> etc, etc.
>
> This takes some time and I am finding that what is happening
> is if the
> server is restarted under load, that the running requests
> grows quickly and
> they are all trying to run these startup tasks. How can I
> make it so that
> only one thread runs these startup tasks and the rest sit and wait
> patiently for those tasks to finish?
>
> Brook Davies
>
>
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to