« Adobe OnAir European Tour
» Adobe AIR for Linux

Java, Adobe, ColdFusion

Force Coldfusion to Sleep controlling the Thread

04.02.08 | 2 Comments

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! :-)

2 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

:

:


« Adobe OnAir European Tour
» Adobe AIR for Linux