ColdFusion 9 - 我的线程持有内存 - 如何停止? [英] ColdFusion 9 - My thread is holding onto memory - how can I stop it?

查看:148
本文介绍了ColdFusion 9 - 我的线程持有内存 - 如何停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特定的线程,我开始时,当CF9应用程序启动。它管理队列并从队列中获取项目以处理它们。如果没有要从队列中取出的项目,它将 sleep()。这个线程可以活几个星期,处理和睡眠等。

I have a particular thread that I kick off when by CF9 application starts. It manages a queue and takes items from the queue to process them. If there are no items to take from the queue it will sleep(). This thread could live for weeks, processing and sleeping etc.

我遇到的问题是,我从队列中取出的项目被保留在堆像在老一代)很长时间,我完成他们。

The problem I am having is that the items I am taking from the queue are being retained in the heap (looks like in the Old Generation) long after I am done with them.

一个完整的垃圾回收由JVM每个小时完成(我可以从jConsole告诉这个),甚至当运行我处理的项目仍然保留堆。我可以告诉这个,因为我做一个 jmap 堆转储,并使用内存分析工具Eclipse插件进行分析。

A full garbage collection is done by the JVM about every hour (I can tell this from jConsole), and even when that runs the items I have processed are still retained in the heap. I can tell this because I do a jmap heap dump and analyse it using the Memory Analysis Tool Eclipse plugin.

这里是我的代码,这是在 Application.cfc

So here is my code, this is executed in Application.cfc:

<!--- Kick off a new thread and run through the queue --->
<cfthread action="run" name="myThread">

    <cfloop condition="APPLICATION.threadProcessing eq true">

        <cfif APPLICATION.myQueue.hasNext()>

            <!--- Get next item --->
            <cfset tmpItem = APPLICATION.myQueue.next() />

            <!--- Ask item to process itself --->
            <cfset tmpItem.process() />

            <!--- PROBLEM: these 'tmpItem' objects are never cleaned up by the garbage collector! ---> 

            <!--- Then we sleep for an interval - this is to stop us hogging server resources --->
            <cfset sleep(2000) />


        <cfelse>

            <!--- Nothing in the queue, so sleep for a while... --->
            <cfset sleep(10000) />

        </cfif>

    </cfloop>   

</cfthread>

任何人都可以告诉我,如果我使用不正确的范围或什么?有办法强制清理我的临时对象吗?我假设调用显式垃圾收集将不会工作,因为它没有被清理反正。

Can anyone tell me if I am using the incorrect scope or something? Is there a way to force cleanup of my temporary objects? I presumed that calling an explicit garbage collection would not work as it's not being cleaned up anyway.

这只会在我们从CF8移动到CF9时出现问题。

This only appeared to become a problem when we moved from CF8 to CF9.

任何和所有帮助 - 我真的想保持这个线程方法,而不是作为一个计划的任务或东西运行它。

Any and all help appreciated - I really would like to keep this thread approach and not run it as a scheduled task or something.

谢谢,Ciaran。

Thanks, Ciaran.

推荐答案

我可以提供两个建议。一个是漂亮的iffy,但另一个是很牢固。

There are two pieces of advice I can offer. One is pretty iffy, but the other is pretty solid.

我被告知,虽然我没有测试它,你可以释放对象的垃圾收集提前通过将空字符串分配给它们的变量名称。基本上,你减少了对象上的指针计数。我只是在CF6.1环境中看到这个,所以我真的不知道它是否会应用,假设它实际工作。

I've been told, though I've not tested it, that you can release objects to garbage collection early by assigning the empty string to their variable name. Essentially, you are reducing the pointer count on the object. I've only seen this done in a CF6.1 environment, so I'm really not sure if it would apply, assuming it actually works.

我会看进入,如果是我,是一个计划的任务。它不会频繁运行(我认为最小等待是1分钟,IIRC),但应该释放任何内存使用的调用,当任务终止。基本上,你只需放弃外层循环和sleep(),并将页面调用为正常调用。我不完全确定你的队列是如何工作的,但由于它在应用程序范围内,所以只要任务在应用程序树中(或包含该应用程序文件),你仍然可以访问它。

What I would look into, if it were me, is a scheduled task. It won't run as often (I think the minimum wait is 1 minute, IIRC) but should free up any memory used by the call when the task terminates. Basically, you just drop the outer loop and the sleep(), and call the page as a normal call. I'm not entirely sure how your queue is working, but since it's in the application scope, you should still be able to access it as long as your task is in the application tree (or includes that application file).

根据你的其他意见,听起来这不是一个共享的环境。您是否有运行计划任务的其他障碍?

Based on your other comments, it sounds like this is not a shared environment. Are there other barriers to you running a scheduled task?

这篇关于ColdFusion 9 - 我的线程持有内存 - 如何停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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