我使用< cfthread>正确的这个解决方案? [英] Am I utilizing <cfthread> correctly for this solution?

查看:310
本文介绍了我使用< cfthread>正确的这个解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过< cffileupload> 标签执行多个图片上传。该标签调用一个名为 fileupload.cfm 的文件来处理/完成图像。



开始一个线程(这里是我可能不理解线程,所以让我知道),以便我可以回复'图像上传'回Flash上​​传应用程序,但启动一个缩略图生成过程(可能持续1分钟左右,取决于文件大小)。



到目前为止,我添加了类似:

 <!---建立一个线程来创建/生成THUMBNAILS ---> 
< cfthread action =runname =t#qMid.mid#>
< cfinvoke component =core.media-functionsmethod =generateThumbnails>
< cfinvokeargument name =midvalue =#qMid.mid#>
< / cfinvoke>
< / cfthread>

我正在调用 generateThumbnails 使用媒体ID(中)作为要处理的项目的参考。我认为线程在我们到达 fileupload.cfm 文件结束时就会死。



不确定如果这只是我应该尝试在所有文件上传后运行的东西?



想法?



经过一些修补之后, ,看起来像我有一个错误与我固定的线程无关,但我应该保持任何内容与'离开'线程这样吗?我应该在某个时候杀死他们吗?他们只是在完成后清理?如何在线程上放置一个最大执行时间?

解决方案

如果你运行一个线程, code>< cfthread action =join/> 在稍后的线程将运行,并行到您的页面执行线程,如果必要的话,完成其任务。



没有问题,线程运行像这样 - 他们将被清理,因为你期望一旦他们完成。



如果你想查看线程是否正在运行,只需运行 cfstat ,它将列出所有正在运行的请求 - 由 cfthread 启动。



您可能已经看过CF文件这里,但进一步检查Ben Nadal的调查此处



对于线程超时 - 您可以指定等待您创建的线程重新加入页面执行的最大时间,但AFAIK没有办法设置超时页面请求超时)。



希望有帮助!


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?

解决方案

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!

这篇关于我使用&lt; cfthread&gt;正确的这个解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆