Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 334

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
• End a thread. You typically end a running thread if there is an error, or if it is still processing after a long time.
• Have the page or a thread wait until one or more other threads have completed processing before proceeding with
its processing, called joining the threads. You typically join threads when one thread requires the results from
another thread. For example, if a page uses multiple threads to get several news feeds for display, it joins all the feed
threads before it displays the results.
Each thread runs the code inside a
processing.
Starting a thread
You start a thread by using a
tag body executes on a separate thread while the page request thread continues processing. Only the page thread can
create other threads. A thread that you create with a
multiple nested threads.
Optionally, when you start the thread, you can specify a priority level of high, normal (the default), or low to specify
the relative amount of time that the processor should devote to the thread. Page-level code always runs at normal
priority, so you can give your threads more or less processing time than the page.
For more information on using thread attributes, see
Suspending a thread
In some cases, one thread must wait until a second thread completes some operations, but should not wait until the
second thread completes all processing, so you cannot just join the threads. For example, one thread might do
initialization that multiple threads require, and then it might continue with additional processing. The other threads
could suspend themselves until initialization is complete.
The
function and
Sleep
cfthread
such synchronization. They suspend the thread processing for a specified period of time. A code loop could test a
condition variable and sleep for a period before retesting the condition. When the condition is true (or a value is
reached, or some other test is valid), the program exits the loop and the thread continues processing.
The following example shows how one thread could use a sleep function to wait for a second thread to perform some
actions.
tag body and normally exits when the tag body code completes
cfthread
tag with an
cfthread
action
cfthread
"The Attributes scope and thread
tag with a
sleepaction
Last updated 1/20/2012
attribute value of
. CFML code within the
run
tag cannot create a child thread, so you cannot have
attributes" on page 333.
attribute provide two equivalent mechanisms for doing
329
cfthread

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents