pf » How to make ColdFusion MX go to sleep
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.
Related Entries
- Thread Priority, and Yielding - April 6, 2005
- Null Java References in CF 6 vs 7 - January 10, 2006
- Checking your JDBC Driver Version - March 31, 2004
- Determining the size of objects in memory - December 10, 2003
- Serializing CFC's in ColdFusion 8 - August 6, 2007
- Force Coldfusion to Sleep controlling the Thread Fusion Team Blog
Any ideas??
Unhandled System exception !
Failed to create JavaVM. JNI_CreateJavaVM returned error code JNI_ERR (this may indicate an unrecognized option string)
Putting the thread to sleep for 5 seconds after the update gave Access enough time to catch up.
<cfset thread = CreateObject("java", "java.lang.Thread")> About to sleep for 5 seconds...<cfflush> <cfset thread.sleep(5000)> Done sleeping. ---------------------
Error: Unhandled System exception ! java.security.AccessControlException: access denied (java.lang.RuntimePermission createClassLoader). Java exception occurred in attempt to construct object.
How do I fix this ?
thanks, mos
You may need to cast your variable that you're sending to sleep to a long via JavaCast. I.E.
<cset thread.sleep(JavaCast('long', yourVariable)) />
HTH, -Umbrae
The app produces a second thread with the same time stamp in the log.
I've seen it with inserts into a database where errors are returned when a key is duplicated by the duplicate thread. Is there any way of catching duplicate threads in CF?
The app produces a second thread with the same time stamp in the log.
I've seen it with inserts into a database where errors are returned when a key is duplicated by the duplicate thread. Is there any way of catching duplicate threads in CF?
When I moved it to a CFC file the 5 second pause was there but the first set of text did not show up until after the pause.
Is this something that can not be done with Components??? Thanks
- Dear SQL Server Enterprise Manager Developer
- PostalMethods - Web Service for Snail Mail
- Mastering CFQUERYPARAM
- Google Code Search for ColdFusion
- Speaking at CFUNITED 2008
- Getting ColdFusion SQL Statements from SQL Server Trace
- CFSCRIPT Cheatsheet
- 3 New Image Effects for ColdFusion 8
RSS
add to del.icio.us
Pete Freitag is a software engineer, and web developer located in











