Implementing Sleep in CF

So I'm trying to import around 10,000 records through loops in CF7, because I have to tack in some additional info for each record... fun. I'd like to sleep the process for a bit, but CF7 doesn't have a built in method for that... Java objects to the rescue.

Java Object Sleep in CF7

<cfset objThread = CreateObject("java", "java.lang.Thread")>
<cfset objThisThread = objThread.currentThread()>
<cfset objThisThread.sleep(500)>

But, as someone at House of Fusion warns:

[The] thread [is] in the queue sleeping, and so if you have configged CF to use max 20 CF threads, and you sleep 20 threads, no requests will be handled by the server unless one of the threads gets free.

Below you can find the syntax for doing this in CF8, as mentioned by Jeff. Thanks for pointing that out Jeff!

<!--- Sleep current thread for 5 seconds --->
<cfset sleep(5000)/>



Jeff Coughlin's Gravatar If you're using CF8 there actually "is" a method in CF now for sleep (coincidently called sleep() :)).

I got that tidbit a couple months back from Charlie Arehart ( who is well-known for his talks about hidden gems in CF.
Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me.

Post a job. Find one.

Interested in becoming a sponsor? Contact me.