Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 323

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
Variable
Server.OS.BuildNumber
Server.OS.Name
Server.OS.Version
Locking code with cflock
The
tag controls simultaneous access to ColdFusion code. The
cflock
• Protect sections of code that access and manipulate shared data in the Session, Application, and Server scopes, and
in the Request and Variables scopes for applications that use ColdFusion threads.
• 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 important for CFX tags that use shared (global) data structures without protecting
them from simultaneous access (not thread-safe). However, Java CFX tags can also access shared resources that
could become inconsistent if the CFX tag access is not locked.
• Ensure that applications do not try to simultaneously access databases that are not thread-safe. (This is not
necessary for most database systems.)
ColdFusion is a multi-threaded web application server that can process multiple page requests at a time. As a result,
the server can attempt to access the same information or resources simultaneously, as the result of two or more
requests.
Although ColdFusion is thread-safe and does not try to modify a variable simultaneously, it does not ensure the correct
order of access to information. If multiple pages, or multiple invocations of a page, attempt to write data
simultaneously, or read and write it at the same time, the resulting data can be inconsistent, as shown in the following
Sample locking scenarios
section.
Similarly, ColdFusion cannot automatically ensure that two sections of code do not attempt to access external
resources such as files, databases, or CFX tags that cannot properly handle simultaneous requests. Nor can ColdFusion
ensure that the order of access to these shared resources is consistent and results in valid data.
By locking code that accesses such resources so that only one thread can access the resource at a time, you can prevent
race conditions.
Sample locking scenarios
The following examples present scenarios in which you need to lock ColdFusion code. These scenarios show only two
of the circumstances where locking is vital.
Reading and writing a shared variable
If you have an application-wide value, such as a counter of the total number of tickets sold, you could have code such
as the following on a login page:
<cfset Application.totalTicketsSold = Application.totalTicketsSold + ticketOrder>
When ColdFusion executes this code, it performs the following operations:
Retrieves the current value of Application.totalTicketsSold from temporary storage.
1
2
Increments this value.
Stores the result back in the Application scope.
3
Description
The specific operating system build, such as 1381
The name of the operating system, such as Windows NT.
The version number of the operating system, such as 4.0.
cflock
Last updated 1/20/2012
tag lets you do the following:
318

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents