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

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

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) />[/xml]

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

[xml]<cfthread action="sleep" duration="1000" />[/xml]

And we can do it via the Sleep function as well

[xml]<cfset sleep(1000) />[/xml]

Tagged with:  

Leave a Reply

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

© 2011 Anuj Gakhar