How to make ColdFusion MX go to sleep

October 14, 2002
coldfusion

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

20 people found this page useful, what do you think?

Trackbacks

Comments

BTW, this also works on CF5!!!!
Very good. Helped me with the problem I was having. Thanks!
I am very frustrated. This code doesn't seem to work! I am getting this error: The JVM library path is empty. To use Java objects or Java CFXs, you need to install (if not already installed) the JDK or JRE and specify the path of the JVM in the ColdFusion Administrator. Please read the release notes regarding the version of the software that is needed. Any ideas??
Two words: Thank you.
I had this error when I patched this code on my template. Pls Help! Unhandled System exception ! Failed to create JavaVM. JNI_CreateJavaVM returned error code JNI_ERR (this may indicate an unrecognized option string)
Code worked beautifully for me. I had a page that updated my Access database, then sent an HTML email which was another webpage that queried the info just updated. The problem was that Access was slower than ColdFusion, so the email you received said nothing had been updated. Putting the thread to sleep for 5 seconds after the update gave Access enough time to catch up.
Thank you, thank you!! I don;t have access to my server to load custom tags so <cfx_sleep> was not an option. This was perfect. Thank you so much!
Any suggestion will be higly appreciated on how to resolve this error "Failed to create JavaVM. JNI_CreateJavaVM returned error code JNI_ERR".
I get the following error when I added the code below <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
<cftry> <!--- your sleep code ---> <cfcatch type="any"> Error-message: sleep interrupted </cfcatch> </cftry>
If you are receiving this error: "The selected method sleep was not found" 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
Er. Thats, "cfset". *cough*
neat! We have a large CF app that has recently migrated from CF 5. I'm investigating a duplicate thread problem that has been discovered. 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?
neat! We have a large CF app that has recently migrated from CF 5. I'm investigating a duplicate thread problem that has been discovered. 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?
This code worked fine when in a CFM to show some text wait 5 seconds and then show some more text. 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
awesome. This will come in handy
wrong ColdFusion
"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."

- try using cfflush

Post a Comment




  



Spell Checker by Foundeo

Recent Entries



foundeo


did you hack my cf?