MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 337

Developing coldfusion mx applications
Table of Contents

Advertisement

If multiple code sections share a lock, the following rules apply:
When code is running in a
tag blocks with the same
cflock
code with the exclusive lock completes.
When code in a
cflock
tag blocks with the same
blocks with the same
all code with the read-only lock completes. However, if a read-only lock is active and code with
an exclusive lock with the same scope or name is waiting to execute, read-only requests using
the same scope or name that are made after the exclusive request is queued must wait until
code with the exclusive lock executes and completes.
Controlling locking access to files and CFX tags with the name attribute
The
attribute provides a second way to identify locks. Use this attribute when you
cflock name
use locks to protect code that manges file access or calls non-thread-safe CFX code.
When you use the
name
specific file or a specific CFX tag.
Controlling and minimizing lock time-outs
You must include a
timeout
maximum time, in seconds, to 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
cflock throwOnTimeout
the line after the
</cflock>
occurs before ColdFusion can acquire the lock. Therefore, never use the
attribute for CFML that must run.
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 of a
1
Assign the result to a Variables scope variable
2
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>
tag block with the
cflock
attribute is not allowed to run. They wait until the
scope
tag block with the type
attribute and the
scope
attribute and an
scope
attribute, specify the same name for each section of code that accesses a
attribute in your
cftry
attribute to No, processing continues after the time-out at
end tag. Code in the
attribute set to
type
is running, code in other
readOnly
readOnly type
type cannot run and must wait until
Exclusive
tag. The
cflock
timeout
and
tags.
cfcatch
tag body does not run if the time-out
cflock
tag
cflock
Locking code with cflock
, code in
Exclusive
cflock
attribute can run, but any
attribute specifies the
throwOnTimeout
block.
cflock
337

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion mx

Table of Contents