Nesting Locks And Avoiding Deadlocks - MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual

Table of Contents

Advertisement

Locking Code with cflock
Automatic read locking also adds overhead because ColdFusion must insert read
locks and check variable access for locking. However, it can be useful if you already
have a site that does not use locking properly. In this case, you must only lock all
writes and do not have to add locks around all reads.
Single-threading sessions
The ColdFusion Administrator also allows you to specify single-threaded sessions. If
you select this option, each session is handled by a single thread in the ColdFusion
Server. As a result, one request from the client must complete before the next one
can begin. In this case, you do not need to lock Session variables, but the
performance of frames-based pages might be reduced because it prevents
simultaneous processing of requests from multiple frames.

Nesting locks and avoiding deadlocks

Inconsistent nesting of
deadlocks (blocked code). If you are nesting locks, you must consistently nest
tags in the same order and use consistent lock scopes (or names).
A deadlock is a state in which no request can execute the locked section of the page.
Thus, all requests to the protected section of the page are blocked until there is a
timeout. The following table shows one scenario that would cause a deadlock:
User 1
Locks the Session scope.
Deadlock: Tries to lock application
scope, but application scope is already
locked by User 2.
Once a deadlock occurs, neither of the users can do anything to break the deadlock,
because the execution of their requests is blocked until the deadlock is resolved by a
lock timeout.
In addition, if you nest locks of different types, you can cause a deadlock. An example
of this is nesting an exclusive lock inside a read lock of the same scope, or of the same
name.
In order to avoid a deadlock, you should lock code sections in a well-specified order
and name the locks consistently. In particular, if you need to lock access to the
Server, Application, and Session scopes, you must do so in the following order.
1
2
3
4
cflock
Lock the Session scope. In the
Lock the Application scope. In the
Lock the Server scope. In the
Unlock the Server scope.
tags and inconsistent naming of locks can cause
User 2
Locks the Application scope.
Deadlock: Tries to lock session, but
session is already locked by User 1.
tag, specify the scope as "session."
cflock
tag, specify the scope as "application."
cflock
tag, specify the scope as "server."
cflock
237
cflock

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 5

Table of Contents