Cflock Examples - MACROMEDIA COLDFUSION 4.5-DEVELOPING WEB Develop Manual

Developing web applications with coldfusion
Table of Contents

Advertisement

200
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 time-
out. The following table shows one scenario that would cause a deadlock.
Deadlock Scenario
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 can be resolved
by a lock time-out.
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 and all who need to nest locks should do so 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.
Lock the session scope. In the CFLOCK tag, specify thescope as "session."
2.
Lock the application scope. In the CFLOCK tag, specify the scope as "application."
3.
Lock the server scope. In the CFLOCK tag, specify the scope as "server."
4.
Unlock the server scope.
5.
Unlock the application scope.
6.
Unlock the session scope.
Note

CFLOCK Examples

The following examples show how to use CFLOCK in a variety of situations.
Example with Application, Server, and Session Variables
This example shows how CFLOCK can be used to guarantee the consistency of data
updates to variables in the Application, Server, and Session scopes.
You can skip any pair of lock/unlock steps in the list above if you don't
need to lock a particular scope. For example, you can take out Steps 3 and
4 if you don't need to lock the server scope.
Developing Web Applications with ColdFusion
User 2
Locks the application scope.
Deadlock: Tries to lock session, but
session is already locked by User 1.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 4.5

Table of Contents