Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 340

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
Variable
Description
Priority
The thread processing priority, as specified when you created the thread.
Starttime
The time at which the thread began processing.
Status
The current status of the thread. For information on using the Status in an application, see
on page 336.
As with other variables in the Thread scope, thread metadata is available to all of a page's threads by specifying the
thread name as a variable prefix. For example, the page thread can get the current elapsed time of the myThread1
thread from the
myThread1.ElapsedTime
The metadata is available from the time that you create the thread until the time when the page and all threads started
on the page complete processing, even if the page finishes before the threads finish. This way, you can get thread
output, error information, and processing information during and after the time when the thread is processing.
Working with threads
Multi-threaded applications use several building blocks, including the following:
• Starting threads in loops
• Getting information about the thread processing status
• Displaying thread results
• Handling thread errors
• Using database transactions with threads
Starting threads inside loops
Because threads run asynchronously, page level variables can change during thread execution. As a result of this
behavior, if you start threads inside a
index variable, query name, list item), pass the loop iterator to the thread as an attribute.
The following example shows the use of threads inside a loop. It uses an indexed
thread gets the current loop index value in a
attribute value of the thread and the current value of the page
threadIndex
the threads, the page displays the array contents. When you run the example, particularly if you run it multiple times,
you see that at the time the thread saves data to the array, the value of
value, and multiple threads often have the same
threadIndex
the correct
value.
threadIndex
<cfloop index="pageIndex" from="1" to="5">
<cfthread name="thr#pageIndex#" threadIndex="#pageIndex#" action="run">
<cfset Variables.theOutput[threadIndex]="Thread index attribute:" &
threadIndex & "&nbsp;&nbsp; Page index value: " & pageIndex>
</cfthread>
</cfloop>
<cfthread action="join" name="thr1,thr2,thr3,thr4,thr5" timeout=2000/>
<cfloop index="j" from="1" to="5">
<cfoutput>#theOutput[j]# <br /></cfoutput>
</cfloop>
variable.
, and code inside the threads uses the value of the loop iterator (like the
cfloop
attribute. The thread adds an array entry with the
threadIndex
pageIndex
Last updated 1/20/2012
"Using the thread
tag to start five threads. Each
cfloop
index,
cfloop
pageIndex
has incremented past the
pageIndex
value; but the multiple threads always have
335
status"
. After joining

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents