
338
Chapter 15: Using Persistent Data and Locking
<cflock scope="Session" timeout="5" type="exclusive">
<cfset Session.qUser = Variables.qUser>
</cflock>
Considering lock granularity
When you design your locking strategy, consider whether you should have multiple locks
containing small amounts of code or few locks with larger blocks of code. There is no simple rule
for making such a decision, and you might do performance testing with different options to help
make your decision. However, you must consider the following issues:
•
If the code block is larger, ColdFusion will spend more time inside the block, which might
increase the number of times an application waits for the lock to released.
•
Each lock requires processor time. The more locks you have, the more processor time is spent
on locking code.
Nesting locks and avoiding deadlocks
Inconsistent nesting of
cflock
tags and inconsistent naming of locks can cause deadlocks
(blocked code). If you are nesting locks, you must consistently nest
cflock
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. 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:
Neither user’s request can proceed, because it is waiting for the other to complete. The two are
deadlocked.
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 time-out.
You can also cause deadlocks if you nest locks of different types. An example of this is nesting an
exclusive lock inside a read-only lock of the same scope or same name.
In order to avoid a deadlock, 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
Lock the Session scope. In the
cflock
tag, specify
scope="Session"
.
2
Lock the Application scope. In the
cflock
tag, specify
scope="Application"
.
3
Lock the Server scope. In the
cflock
tag, specify
scope="Server"
.
4
Unlock the Server scope.
5
Unlock the Application scope.
6
Unlock the Session scope.
User 1
User 2
Locks the Session scope.
Locks the Application scope.
Tries to lock the Application scope, but the
Application scope is already locked by User 2.
Tries to lock the Session scope, but the Session
scope is already locked by User 1.
Содержание ColdFusion MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...