How to make ColdFusion MX go to sleep
Many people have had the need for a ColdFusion page to sleep, typically between iterations of a loop. There is a tag called CFX_Sleep in the Tag Gallery, but in ColdFusion MX you don't need a CFX tag to make the current processing thread sleep using the static sleep method on the java.lang.Thread class, part of the standard java platform. Because CFMX doesn't allow us to call a static method without an object reference, we have to first use CreateObject, or CFOBJECT to get an instance of a java.lang.Thread object. We then call the Thread.sleep(long) method, which takes in the number of miliseconds to sleep for.
<cfset thread = CreateObject("java", "java.lang.Thread")> About to sleep for 5 seconds...<cfflush> <cfset thread.sleep(5000)> Done sleeping.
Like this? Follow me ↯Tweet Follow @pfreitag
How to make ColdFusion MX go to sleep was first published on October 14, 2002.
If you like reading about thread, cfml, sleep, cfobject, or java then you might also like:
- Thread Priority, and Yielding
- Null Java References in CF 6 vs 7
- Checking your JDBC Driver Version
- Determining the size of objects in memory
- URL Safe Base64 Encoding / Decoding in CFML
- Getting Size of Heap and Non Heap Memory in CFML
- CFML on Google App Engine for Java
- Serializing CFC's in ColdFusion 8
The FuseGuard Web Application Firewall for ColdFusion & CFML is a high performance, customizable engine that blocks various attacks against your ColdFusion applications.