Question

I am trying to do multiple image uploads via the <cffileupload> tag. The tag calls a file called fileupload.cfm to process / finalize the image.

Inside that image I want to start off a thread (here is where I might not understand threading, so let me know) so that I can reply 'image uploaded' back to the flash upload app, but initiate a thumbnail generation process (which might last 1 min or so, depending on the file size).

So far I added something like:

<!--- BUILD A THREAD TO CREATE / GENERATE THUMBNAILS --->
<cfthread action="run" name="t#qMid.mid#">
    <cfinvoke component="core.media-functions" method="generateThumbnails">
        <cfinvokeargument name="mid" value="#qMid.mid#">
    </cfinvoke> 
</cfthread>

I am calling the generateThumbnails method, and using a media id (mid) as reference on which item to process. I think the thread dies tho as soon as we reach the end of the fileupload.cfm file.

Not sure if this is just something I should try to run after all files are uploaded?

Thoughts? Not sure how to get this working properly.

EDIT

After some tinkering, looks like I had an error unrelated to the thread which I fixed, but should I keep anything in mind with 'leaving' threads like this? Should I kill them at some point? Will they just be cleaned up after completion? How can I put a 'max execution time' on a thread?

Was it helpful?

Solution

If you run a thread and do not actually call <cfthread action="join" /> at some point later the thread will run, in parallel to your page execution thread, and if necessary will run for much longer until it completes its task.

There is no problem leaving threads run like this - they will be cleaned up as you'd expect once they complete.

If you want to see if a thread is running just run cfstat which will list all running requests - even ones kicked off by cfthread.

You've probably seen the CF docs here but further to that check out Ben Nadal's investigation here.

As for thread timeouts - you can specify a max time to wait for threads you created to rejoin page execution, but AFAIK there is no way to put a timeout (like a page request timeout) on the thread you created.

Hope that helps!

OTHER TIPS

One note:

The docs talk about "zero or more application-specific attributes". I would pay attention to this. This creates a local copy of the variable, allowing you to pass in values that won't be changed.

So, I would call

<cfthread action="run" name="t#qMid.mid#" mid="#qMid.mid#">
    <cfinvoke component="core.media-functions" method="generateThumbnails">
        <cfinvokeargument name="mid" value="#mid#">
    </cfinvoke> 
</cfthread>

Make sense?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top