|
The CFTHREAD Scope
By Raymond Camden
Expert Author
Article Date: 2007-07-27
Did you know that ColdFusion 8 has a new scope? The CFTHREAD scope is a special scope that contains information about threads in the current request.
Consider this simple example:
<cfset urls =
"http://www.cnn.com,http://www.coldfusionjedi.com,
http://www.yahoo.com">
<cfset counter = 0>
<cfloop index="u" list="#urls#">
<cfset counter++ >
<cfthread theurl="#u#" name="thread_#counter#">
<cfhttp url="#attributes.theurl#">
</cfthread>
</cfloop>
<cfdump var="#cfthread#">
This code block creates 3 threads, named thread_1, thread_2, and thread_3. (I don't get paid to be creative!) Each thread created will exist as a structure inside the CFTHREAD scope as demonstrated in this screen shot:
You will notice that not all of my threads are finished. That is because I didn't do a join on my threads. If you look at Paragator, my ColdFusion RSS Aggregator CFC, you will see I kept a list of all threads so that I could join them. I then used Evalute to create pointers to the data. This can be done a lot easier now. So for example, to join all threads:
<cfthread action="join" name="#structKeyList(cfthread)#" />
And to get access to a thread's data:
<cfdump var="#cfthread[somethreadname]#">
I'll be updating Paragator a bit later in the week.
Comments
About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com
Raymond Camden is Vice President of Technology for roundpeg, Inc. A long
time ColdFusion user, Raymond has worked on numerous ColdFusion books
and is the creator of many of the most popular ColdFusion community web
sites. He is an Adobe Community Expert, user group manager, and the
proud father of three little bundles of joy.
|
|