22.08.2013 Views

ColdFusion Developer's Guide

ColdFusion Developer's Guide

ColdFusion Developer's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta<br />

CHAPTER 16<br />

Using <strong>ColdFusion</strong> Threads<br />

You can use threads in <strong>ColdFusion</strong> to simultaneously run multiple streams of execution in a<br />

<strong>ColdFusion</strong> page or CFC.<br />

Contents<br />

About <strong>ColdFusion</strong> threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439<br />

Creating and managing CF threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440<br />

Using thread data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444<br />

Working with threads. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .448<br />

Using <strong>ColdFusion</strong> tools to control thread use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450<br />

Example: getting multiple RSS feeds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451<br />

About <strong>ColdFusion</strong> threads<br />

Threads are independent streams of execution. Multiple threads on a page or CFC can<br />

execute simultaneously and asynchronously, letting you perform asynchronous processing in<br />

CFML.<br />

Threads are useful for two broad types of activities:<br />

■ Where multiple actions can occur simultaneously.<br />

■ Where you do not have to wait for one action to complete before starting the next action.<br />

Some typical uses for threads include the following examples:<br />

■ An application that aggregates information from multiple external sources that might take<br />

significant times to respond could have the code that gets information from each source in<br />

a separate thread. This way, the application starts all requests quickly and has to wait only<br />

until the last response is received, instead of having to wait for a response to each request<br />

before the next request can start. One example of such usage is an RSS or Atom feed<br />

aggregator.<br />

439<br />

16

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!