|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
ColdFusion News Desk Multi-Threaded Application Development In ColdFusion 8
ColdFusion MX7 introduced the ability to asynchronously spawn ColdFusion requests using an event gateway
By: Ben Forta
Jun. 2, 2007 06:00 PM
ColdFusion MX7 introduced the ability to asynchronously spawn ColdFusion requests using an event gateway. While many take advantage of this capability, it has some significant limitations, the biggest of which is that threads can only be spawned, there is no way to monitor spawned threads or wait for them to finish. (The other limitation is that the functionality is only available in ColdFusion Enterprise).
ColdFusion Scorpio provides far more sophisticated multi-threading capabilities via the new <CFTHREAD> tag. This tag is used to perform several actions:
There are lots of use cases for this new functionality, but at a minimum there are two primary usage scenarios:
The code to spawn a thread is very simple: <!--- Use a separate thread to perform file processing ---> <cfthread action="run" name="threadFile" file="#myFile#"> <cffile file="#ATTRIBUTES.file#" ...> </cfthread> Here a thread named 'threadFile' is spawned. An argument (the file to be processed) is passed to <CFTHREAD>, and so that attribute is available within the thread in the ATTRIBUTES scope. Within threads there are several important scopes. Any locally defined variables are implicitly thread local. THREAD is a special scope (a sub-scope of VARIABLES) that is available to all threads spawned by a single parent. ATTRIBUTES is used to access any variables passed as attributes to <CFTHREAD>. The previous example spawns a thread that could continue processing long after the parent page terminates. If you needed to wait for a thread to complete you could use the following code: <cfthread action="join" name="threadFile"> JOIN is used to wait for one or more threads to complete, and multiple thread names may be specified (as may a timeout value). Once defined, the thread name can be accessed as a structure which exposes the following members:
So, to check that threads executed properly without errors, you could JOIN the threads, and then check STATUS to see if they completed. A status of TERMINATED means an error occurred (or that threads were explicitly terminated) in which case ERROR would provide details as to what happened. Reader Feedback: Page 1 of 1
Your Feedback
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||