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.
Tweet
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 11, 2003
- CFML on Google App Engine for Java - April 10, 2009
Trackbacks
- Force Coldfusion to Sleep controlling the Thread Fusion Team Blog
Comments
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
- try using cfflush
Post a Comment
Recent Entries
- Firefox Aurora now Supports Content Security Policy 1.0
- Writing Secure CFML cfObjective 2013 Slides
- Upgrading to Java 7 on Linux
- J2EE Sessions in CF10 Uses Secure Cookies
- Learn about ColdFusion Security at cfObjective 2013
- Session Loss and Session Fixation in ColdFusion
- FuseGuard 2.3 Released
- CKEditor Spell Checker Plugin


add to del.icio.us



