MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 336

Developing coldfusion mx applications
Table of Contents

Advertisement

Lock types
The
tag offers two modes of locking, specified by the
cflock
Exclusive locks
No other requests can run code inside the tag while a request has an exclusive lock.
Enclose all code that creates or modifies session,application, or server variables in exclusive
tags.
cflock
Read-only locks
the same scope or name are executing. No requests can run code inside the tag while a request
has an exclusive lock.
Enclose code that only reads or tests session, application, or server variables in read-only
tags. You specify a read-only lock by setting the
cflock
tag, for example:
cflock
<cflock scope="Application" timeout="10" type="readOnly">
<cfif IsDefined("Application.dailyMessage")>
<cfoutput>#Application.dailyMessage#<br></cfoutput>
</cfif>
</cflock>
Although ColdFusion does not prevent you from setting shared variables inside read-only lock
tag, doing so loses the advantages of locking. As a result, you must be careful not to set any
session, application, or server variables inside a read-only
Note: You cannot upgrade or downgrade a lock from one type to another. In other words, do not nest
an exclusive lock in a read-only lock of the same name or scope; the exclusive lock will always time
out. Also, do not nest a read-only lock inside an exclusive lock with the same name or scope; doing so
has no effect.
Lock scopes and names
The
tag prevents simultaneous access to sections of code, not to variables. If you have two
cflock
sections of code that access the same variable, they must be synchronized to prevent them from
running simultaneously. You do this by identifying the locks with the same
attributes.
Note: ColdFusion does not require you to identify exclusive locks. If you omit the identifier, the lock is
anonymous and you cannot synchronize the code in the
Anonymous locks do not cause errors when they protect a resource that is used in a single code
block, but they are bad programming practice. You must always identify read-only locks.
Controlling access to data with the scope attribute
When the code that you are locking accesses session, application, or server variables, synchronize
access by using the
You can set the attribute to any of the following values:
Scope
Server
Application
Session
336
Chapter 15: Using Persistent Data and Locking
(the default lock type) Allow only one request to process the locked code.
Allow multiple requests to execute concurrently if no exclusive locks with
attribute.
cflock scope
Meaning
All code sections with this attribute on the server share a single lock.
All code sections with this attribute in the same application share a single lock.
All code sections with this attribute that run in the same session of an application
share a single lock.
attribute:
type
type="readOnly"
tag body.
cflock
scope
tag block with any other code.
cflock
attribute in the
or
name

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents