Adobe COLDFUSION 9 Manual page 327

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
Controlling and minimizing lock time-outs
Include a
attribute in your
timeout
wait to obtain the lock if it is not available. By default, if the lock does not become available within the time-out period,
ColdFusion generates a Lock type exception error, which you can handle using
If you set the
cflockthrowOnTimeout
end tag. Code in the
</cflock>
the lock. Therefore, never use the
Normally, it does not take more than a few seconds to obtain a lock. Very large time-outs can block request threads
for long periods of time and radically decrease throughput. Always use the smallest time-out value that does not result
in a significant number of time-outs.
To prevent unnecessary time-outs, lock the minimum amount of code possible. Whenever possible, lock only code
that sets or reads variables, not business logic or database queries. One useful technique is to do the following:
Perform a time-consuming activity outside a
1
2
Assign the result to a Variables scope variable
Assign the Variables scope variable's value to a shared scope variable inside a
3
For example, if you want to assign the results of a query to a session variable, first get the query results using a Variables
scope variable in unlocked code. Then, assign the query results to a session variable inside a locked code section. The
following code shows this technique:
<cfquery name="Variables.qUser" datasource="#request.dsn#">
SELECT FirstName, LastName
FROM Users
WHERE UserID = #request.UserID#
</cfquery>
<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, consider the following issues:
• If the code block is larger, ColdFusion spends more time inside the block, which can 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
nesting locks, you must consistently nest
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:
tag. The
cflock
timeout
attribute to No, processing continues after the time-out at the line after the
tag body does not run if the time-out occurs before ColdFusion can acquire
cflock
attribute for CFML that must run.
throwOnTimeout
tag
cflock
tags and inconsistent naming of locks can cause deadlocks (blocked code). If you are
tags in the same order and use consistent lock scopes (or names).
cflock
Last updated 8/5/2010
attribute specifies the maximum time, in seconds, to
and
cftry
block.
cflock
tags.
cfcatch
322

Advertisement

Table of Contents
loading

Table of Contents