Using Cflock; Avoiding Deadlocks - MACROMEDIA COLDFUSION 4.5-DEVELOPING WEB Develop Manual

Developing web applications with coldfusion
Table of Contents

Advertisement

Chapter 12: Using the Application Framework
Exclusive locks allow only one request to process the locked code.
Read-only locks allow multiple requests to execute concurrently, provided that
no exclusive locks are executing.
Note

Using CFLOCK

ColdFusion Server is a multi-threaded web application server that can process
multiple page requests at any given time. Use CFLOCK to guarantee that multiple
concurrently executing requests do not manipulate shared data structures, files, or
CFXs in an inconsistent manner.
Note the following:
Using CFLOCK around CFML constructs that modify shared data ensures that
the modifications occur one after the other and not all at the same time.
Using CFLOCK around file manipulation constructs can guarantee that file
updates do not fail due to files being open for writing by other applications or
ColdFusion tags.
Using CFLOCK around CFX invocations can guarantee that CFXs that are not
implemented in a thread-safe manner can be safely invoked by ColdFusion.
This usually only applies to CFXs developed in C++ using the CFAPI. Any C++
CFX that maintains and manipulates shared (global) data structures will have to
be made thread-safe to safely work with ColdFusion. However, writing thread-
safe C++ CFXs requires advanced knowledge. A CFML custom tag wrapper can
be used around the CFX to make its invocation thread-safe.
Note

Avoiding deadlocks

Be sure to nest CFLOCK tags consistently. A potential cause of blocked request threads
is inconsistent nesting of CFLOCK tags and inconsistent naming of locks. If you are
nesting locks, you and everyone accessing the locked variables must consistently nest
CFLOCK tags in the same order and use the same lock name for each scope. If
everyone accessing locked variables does not adhere to these conventions, a deadlock
can occur.
Unless you specify the TYPE attribute, the default lock is exclusive. You
should minimize the use of exclusive locks. If you have performance-
sensitive code inside CFLOCK tags, consider adding the
TYPE="ReadOnly" attribute to CFLOCK tags that do not update shared
data.
CFLOCK uses a kernel-level synchronization object that is released
automatically upon time-out and/or abnormal termination of the thread
that owns it. Therefore, ColdFusion will never deadlock for an infinite
period of time while processing a CFLOCK tag. However, very large time-
outs can block request threads for long periods of time and thus radically
decrease throughput. Always use the minimum time-out value allowed.
199

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION 4.5-DEVELOPING WEB and is the answer not in the manual?

This manual is also suitable for:

Coldfusion 4.5

Table of Contents