
Locking Code with cflock
233
Locking Code with cflock
The
cflock
tag controls simultaneous access to ColdFusion code. The
cflock
tag
enables you to:
•
Protect sections of code that access and manipulate shared data such as Session,
Application, and Server variables.
•
Ensure that file updates do not fail because files are open for writing by other
applications or ColdFusion tags.
•
Ensure that applications do not try to simultaneously access ColdFusion
extension tags written using the CFX API that are not thread-safe. This is only
necessary for CFX tags that are written in C++ and use shared (global) data
structures without protecting them from simultaneous access (are not
thread-safe).
•
Ensure that applications do not try to simultaneously access databases that are
not thread-safe. This is not necessary for most database systems.
Failure to use
cflock
in these circumstances can result in data corruption and can
result in hanging the ColdFusion Server. Symptoms of this corruption include the
following:
•
Unexpected error messages, particularly Unknown Exception errors
•
cfserver process crashing, or stopping and restarting
•
Unexpected values in shared variables
•
Excessive growth in memory used by the cfserver process
•
Operating system instability
Using cflock
You protect access to code by surrounding it in a
cflock
tag; for example:
<cflock scope="Application"
timeout="10"
type="Exclusive">
<cfif not isdefined("application.number")>
<cfset Application.number = 1>
</cfif>
</cflock>
How cflock works
ColdFusion Server is a multithreaded Web application server that can process
multiple page requests at a time. As a result, the server can attempt to access the
same information simultaneously as the result of two or more requests. While it is
safe to read data simultaneously, attempting to write data simultaneously or read
and write it at the same time can result in corrupted memory and can cause the
process to crash.
Содержание COLDFUSION 5-DEVELOPING
Страница 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Страница 58: ...38 Chapter 3 Querying a Database ...
Страница 134: ...114 Chapter 7 Updating Your Database ...
Страница 210: ...190 Chapter 10 Reusing Code ...
Страница 232: ...212 Chapter 11 Preventing and Handling Errors ...
Страница 238: ...218 Chapter 12 Using the Application Framework ...
Страница 262: ...242 Chapter 12 Using the Application Framework ...
Страница 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Страница 320: ...300 Chapter 15 Indexing and Searching Data ...
Страница 336: ...316 Chapter 16 Sending and Receiving E mail ...
Страница 374: ...354 Chapter 18 Interacting with Remote Servers ...