Adobe COLDFUSION 9 Manual page 329

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
3
If it the local variable indicates that the application variables are not initialized, get an exclusive Application scope lock.
Inside the lock, again test the Application scope flag, to make sure that another page has not set the variables
4
between step one and step four.
If the variables are still not set, set them and set the Application scope flag to true.
5
6
Release the exclusive lock.
The following code shows this technique:
<!--- Initialize local flag to false. --->
<cfset app_is_initialized = False>
<!--- Get a readonly lock --->
<cflock scope="application" type="readonly">
<!--- read init flag and store it in local variable --->
<cfset app_is_initialized = IsDefined("APPLICATION.initialized")>
</cflock>
<!--- Check the local flag --->
<cfif not app_is_initialized >
<!--- Not initialized yet, get exclusive lock to write scope --->
<cflock scope="application" type="exclusive">
<!--- Check nonlocal flag since multiple requests could get to the
exclusive lock --->
<cfif not IsDefined("APPLICATION.initialized") >
<!--- Do initializations --->
<cfset APPLICATION.varible1 = someValue >
...
<!--- Set the Application scope initialization flag --->
<cfset APPLICATION.initialized = "yes">
</cfif>
</cflock>
</cfif>
Examples of cflock
The following examples show how to use
Example with application, server, and session variables
This example shows how you can use
Application, Server, and Session scopes.
This example does not handle exceptions that arise if a lock times out. As a result, users see the default exception error
page on lock time-outs.
The following sample code might be part of the Application.cfm file:
blocks in a variety of situations.
cflock
to guarantee the consistency of data updates to variables in the
cflock
Last updated 8/5/2010
324

Advertisement

Table of Contents
loading

Table of Contents