![MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual Download Page 261](http://html1.mh-extra.com/html/macromedia/coldfusion-5-developing/coldfusion-5-developing_develop-manual_3293641261.webp)
Examples of cflock
241
Example of synchronizing access to a file system
The following example shows how to use
cflock
to synchronize access to a file
system. The
cflock
tag protects a
cffile
tag from attempting to append data to a
file already open for writing by the same tag executing on another request.
Note that if an append operation takes more that 30 seconds, a request waiting to
obtain an exclusive lock to this code might time out. Also, note the use of a dynamic
value for the
name
attribute so that a different locks controls access to each file. As a
result, locking access to one file does not delay access to any other file.
<cflock name=#filename# timeout=30 type="Exclusive">
<cffile action="Append"
file=#fileName#
output=#textToAppend#>
</cflock>
Example of protecting ColdFusion Extensions
The following example illustrates how you can build a custom tag wrapper around a
CFX tag that is not thread-safe. The wrapper forwards attributes to the
non-thread-safe CFX tag that is used inside a
cflock
tag.
<cfparam name="Attributes.AttributeOne" default="">
<cfparam name="Attributes.AttributeTwo" default="">
<cfparam name="Attributes.AttributeThree" default="">
<cflock timeout=5
type="Exclusive"
name="cfx_not_thread_safe">
<cfx_not_thread_safe attributeone=#attributes.attributeone#
attributetwo=#attributes.attributetwo#
attributethree=#attributes.attributethree#>
</cflock>
Summary of Contents for COLDFUSION 5-DEVELOPING
Page 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Page 58: ...38 Chapter 3 Querying a Database ...
Page 134: ...114 Chapter 7 Updating Your Database ...
Page 210: ...190 Chapter 10 Reusing Code ...
Page 232: ...212 Chapter 11 Preventing and Handling Errors ...
Page 238: ...218 Chapter 12 Using the Application Framework ...
Page 262: ...242 Chapter 12 Using the Application Framework ...
Page 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Page 320: ...300 Chapter 15 Indexing and Searching Data ...
Page 336: ...316 Chapter 16 Sending and Receiving E mail ...
Page 374: ...354 Chapter 18 Interacting with Remote Servers ...