Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 326

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
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, be careful not to set any session, application, or server variables inside a read-only
tag body.
cflock
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 sections of code that
cflock
access the same variable, they must be synchronized to prevent them from running simultaneously. You do this by
identifying the locks with the same
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
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
attribute.
cflockscope
You can set the attribute to any of the following values:
Scope
Meaning
Server
All code sections with this attribute on the server share a single lock.
Application
All code sections with this attribute in the same application share a single lock.
Session
All code sections with this attribute that run in the same session of an application share a single lock.
Request
All code sections with this attribute that run in the same request share a single lock. You use this scope only if your
application uses the
locks access to Variables scope data. For more information on locking the Request scope, see
and resource
If multiple code sections share a lock, the following rules apply:
• When code is running in a
with the same
attribute is not allowed to run. They wait until the code with the exclusive lock completes.
scope
• When code in a
tag block with the type
cflock
attribute and the
scope
readOnlytype
type cannot run and must wait until all code with the read-only lock completes. However, if a read-only
Exclusive
lock is active and code with an exclusive lock with the same scope or name is waiting to execute, read-only requests
using the same scope or name that are made after the exclusive request is queued must wait until code with the
exclusive lock executes and completes.
Controlling locking access to files and CFX tags with the name attribute
The
attribute provides a second way to identify locks. Use this attribute when you use locks to protect
cflockname
code that manges file access or calls non-thread-safe CFX code.
When you use the
attribute, specify the same name for each section of code that accesses a specific file or a specific
name
CFX tag.
or
attributes.
scope
name
tag block with any other code. Anonymous locks do not cause errors when
cflock
cfthread
tag to create multiple threads in a single request. Locking the Request scope also
access" on page 334.
tag block with the
cflock
type
readOnly
attribute can run, but any blocks with the same
Last updated 1/20/2012
attribute set to
Exclusive
is running, code in other
cflock
"Locking thread data
, code in
tag blocks
cflock
tag blocks with the same
attribute and an
scope
321

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents