Different ways of making a Thread Sleep

On January 23, 2008, in ColdFusion, by Anuj Gakhar

There are several occasions when we need to stop processing the page for a period of time. Before the release of Coldfusion 8, we could use Java’s sleep function to do that. The purpose of this post is to list the ways available to make a thread sleep in server side code.

Here is the first one, the most common one :-

<cfset javaObj = createObject("java", "java.lang.Thread")>
<cfset javaObj.sleep(1000) />

With the release of Coldfusion 8, we can now also use the native .NET objects from within Coldfusion, here is how this can be done using .NET objects.

<cfset netObj = createObject("dotnet","System.Threading.Thread")>
<cfset netObj.sleep(1000) />

And last but not the least, Coldfusion 8 supports this via the CFTHREAD tag as well.

<cfthread action="sleep" duration="1000" />

And we can do it via the Sleep function as well

<cfset sleep(1000) />
Tagged with:  

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 445 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: