User Guide

Table Of Contents
Examples of cflock 371
Example of synchronizing access to a file system
The following example shows how to use a
cflock block 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.
If an append operation takes more than 30 seconds, a request waiting to obtain an exclusive lock
to this code might time out. Also, this example uses a dynamic value for the
name attribute so that
a different lock 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 shows 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>