I ran into an annoying problem today, that was eventually solved by forcing the current processing thread to sleep.
The basic task was to stop a windows service on the server, perform some deletions, do some copying, then restart the service.
After issuing the <cfexecute> command to stop the service on the server, I would then receive a ColdFusion error when trying to delete a folder that the service still had locked. Whilst this had me stumped for a good hour or so, I finally realised that the deletion event was occurring too quickly after the service had been stopped and that the service still had a lock on the folder and files through the Windows OS.
So I needed a way to pause the current processing thread, before continuing, allowing the locks to be removed. I found this solution on Peter Freitag’s blog post “How to make ColdFusion MX go to sleep”. The solution is as follows …
<cfset thread = CreateObject(”java”, “java.lang.Thread”)>
About to sleep for 5 seconds…
<cfflush>
<cfset thread.sleep(5000)>
Done sleeping.
<cfset thread = “” />
Very simple code, but done the trick and works a treat! ![]()

Or you could use
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_t_04.html
This will work on CF8 only.
Hello Everybody,
I have a question in concerns to threads. We all know that in CF8 we have this fantastic tag called which give us the ability to create assyncronous code, however, I was concerned about earlier versions of ColdFusion, like CF7 and CF 6.1.
After looking at some examples out there, I kind of came with some kind of “example” but I don’t know if it’s right. Here’s the example:
…
SET NOCOUNT ON
SELECT
countryId
FROM countries
WHERE countryCode = SET NOCOUNT OFF
How can I create a Java thread and use it in my CF code? Please, any help is much appreciated.
Thanks in advance.
Alvaro Costa
Systems Analyst
alvaro.galdino@gmail.com