Welcome!

Silverlight Authors: Michael Sheehan, Hovhannes Avoyan, Yeshim Deniz, Maureen O'Gara, Mark O'Neill

Related Topics: ColdFusion

ColdFusion: Article

Adobe ColdFusion 8 Tips

A compilation of Ben Forta's blog entries from his ColdFusion 8 user group tour

In addition to the <CFLOOP> enhancements, we've also added lots of new file i/o functions that you can use to access and manipulate files directly. The new functions include:

  • FileClose()
  • FileCopy()
  • FileDelete()
  • FileIsEOF()
  • FileMove()
  • FileOpen()
  • FileRead()
  • FileReadBinary()
  • FileReadLine()
  • FileSetAccessMode()
  • FileSetAttribute()
  • FileSetLastModified()
  • FileWrite()
  • GetFileInfo()
  • IsImageFile()
  • IsPDFFile()
ColdFusion 8 Makes Obtaining Database and Table Info Easy
This feature was first demonstrated at a usergroup presentation in Connecticut: a new tag in ColdFusion 8 named <CFDBINFO> that returns information about databases (and data sources, and tables, and columns, and stored procedures, and more). This first code snippet shows how to obtain a list of tables in a specified data source (using the default database):

<cfdbinfo type="tables" datasource="myDSN" name="tables">

To get column details you can do the following:

<cfdbinfo type="columns" datasource="myDSN" table="myTables" name="columns">

This would return a query containing column names, type, size, default values, whether it allows NULL values, key associations, and more.

As you can see, <CFDBINFO> accepts a TYPE attribute that tells it what information you want, and the following types are supported:

  • columns: Returns column details for a specific table.
  • dbnames: Returns the databases in a specified data source.
  • foreignkeys: Returns foreign key name information, including the associated primary key, and delete and update rules.
  • index: Returns index specifics, including column details, page usage, and whether or not the index is unique.
  • procedures: Returns available stored procedures.
  • tables: Returns the names of tables within a specific database.
  • version: Returns database drive version details.
Multi-Threaded Application Development in ColdFusion 8
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 8 provides far more sophisticated multi-threading capabilities via the new <CFTHREAD> tag. This tag is used to perform several actions:

  • JOIN causes the current thread to wait until one or more specified threads have finished processing.
  • RUN creates a new thread that starts processing immediately.
  • SLEEP makes another thread pause for a specified number of milliseconds.
  • TERMINATE kills another thread.
There are lots of use cases for this new functionality, but at a minimum there are two primary usage scenarios:

• Many requests process user submissions, for example, a user uploaded file. The way most ColdFusion applications work today is that the file is processed on the server (parsing it, converting it, saving it, etc.) while the user waits. But in truth, there is no reason users should have to wait for your application to finish its processing. A better user experience would be to receive the file in the action page, spawn a new thread to actually process it, and return control back to the user instantly. This creates a far more responsive user experience.
• Applications often have to perform multiple operations (perhaps updating database rows, writing log entries, generating an e-mail, firing server-side HTTP requests, and more). Most ColdFusion applications perform these tasks sequentially, one after the other, and then return to the user when complete. But if the various operations are not actually dependent on each other, you could spawn a thread for each, having them execute concurrently and, if necessary, wait until they are complete to continue processing. The result is a faster application, as multiple operations are being performed concurrently.

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>.

More Stories By Ben Forta

Ben Forta is Adobe's Senior Technical Evangelist. In that capacity he spends a considerable amount of time talking and writing about Adobe products (with an emphasis on ColdFusion and Flex), and providing feedback to help shape the future direction of the products. By the way, if you are not yet a ColdFusion user, you should be. It is an incredible product, and is truly deserving of all the praise it has been receiving. In a prior life he was a ColdFusion customer (he wrote one of the first large high visibility web sites using the product) and was so impressed he ended up working for the company that created it (Allaire). Ben is also the author of books on ColdFusion, SQL, Windows 2000, JSP, WAP, Regular Expressions, and more. Before joining Adobe (well, Allaire actually, and then Macromedia and Allaire merged, and then Adobe bought Macromedia) he helped found a company called Car.com which provides automotive services (buy a car, sell a car, etc) over the Web. Car.com (including Stoneage) is one of the largest automotive web sites out there, was written entirely in ColdFusion, and is now owned by Auto-By-Tel.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
turbotad 07/02/09 11:42:00 PM EDT

Question: I'm pretty new to ColdFusion, but am more experienced running J2EE type boxes. I'm trying to set up a ColdFusion dev server on a VM with limited memory, and I'm trying to trim it back so that it doesn't pork out and use every bit of memory on any computer within a 10 mile radius. I.e. trying to get it so that it perhaps doesn't fire up all of the Flash remoting servlets or other things I don't need for basic CF functionality, in hopes that this might trim back the RAM usage. Any help you might be able to be on this?