GC循环中Finalize对象的问题 [英] Problem with Finalize objects in GC cycle

查看:72
本文介绍了GC循环中Finalize对象的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我们正在使用verboseGC监控应用程序。在我们的应用程序中,我们有大量的finalize方法。我们已经通过VerboaseGC日志观察到许多Finalize对象已经在每个GC循环中排队。

我们知道垃圾回收器需要至少两个周期(可能更多的GC周期)来回收Finalize对象并且需要保留在此过程中可从其访问的所有其他对象。但有没有其他方法来调整这个问题,无法再次重写应用程序代码。

请帮助我。


VerboaseGC日志:


GC日志中很少有终结对象排队参数的样本:


< finalization objectsqueued =" 198" />

< finalization objectsqueued =" 3960" />

< finalization objectsqueued =" 1102" />

< finalization objectsqueued =" 690" />

< finalization objectsqueued =" 63" />

< finalization objectsqueued =" 206" />

< finalization objectsqueued =" 75" />

< finalization objectsqueued =" 1034" />

< finalization objectsqueued =" 740" />

< finalization objectsqueued =" 684" />

< finalization objectsqueued =" 1110" />

< finalization objectsqueued =" 762" />

< finalization objectsqueued =" 1142" />

解决方案

想象一下以下人为场景:

展开 | 选择 | 换行 | 行号


你好Jos,


非常感谢您的善意建议。这意味着除了更改应用程序之外没有其他选择。你有什么建议?有没有有效的方法来改变finalize方法?


谢谢和问候,

Rishi。


< blockquote class =post_quotes>
想象一下以下人为场景:

展开 | 选择 | Wrap | 行号



你好乔斯,


非常感谢您的善意建议。这意味着除了更改应用程序之外没有其他选择。你有什么建议?有没有有效的方法来改变finalize方法?


谢谢和问候,

Rishi。



我会说没有实现终结器;对于真正的资源(打开文件,套接字等)

一旦你完成它们就关闭它们;不要拖延到最终确定

阶段。如果你完成了POJO(普通旧Java对象),你可以将它的

引用设置为null a.s.a.p.但是不要使用终结器;正如我写的:他们是一团糟。


Hi ,

We are monitoring the applications using the verboseGC. And in our application we have large number of finalize method. We have observed through VerboaseGC logs that lots of Finalize objects has queued up on each GC cycle.
And We know that the garbage collector needs a minimum of two cycles (maybe more GC cycles) to reclaim Finalize objects and needs to retain all other objects reachable from them during this process. But is there any other way to tune this problem irrespacting of rewrite the application code again.
Please help me on this.

VerboaseGC logs:

Few sample of finalization objects queued parameter in GC logs:

<finalization objectsqueued="198" />
<finalization objectsqueued="3960" />
<finalization objectsqueued="1102" />
<finalization objectsqueued="690" />
<finalization objectsqueued="63" />
<finalization objectsqueued="206" />
<finalization objectsqueued="75" />
<finalization objectsqueued="1034" />
<finalization objectsqueued="740" />
<finalization objectsqueued="684" />
<finalization objectsqueued="1110" />
<finalization objectsqueued="762" />
<finalization objectsqueued="1142" />

解决方案

Imagine the following artificial scenario:

Expand|Select|Wrap|Line Numbers


Hi Jos,

Thank you very much for your kind suggestion. This means there is no other alternative except change the application. What do you suggest? Is there any efficient way to change the finalize method?

Thanks and regards,
Rishi.


Imagine the following artificial scenario:

Expand|Select|Wrap|Line Numbers


Hi Jos,

Thank you very much for your kind suggestion. This means there is no other alternative except change the application. What do you suggest? Is there any efficient way to change the finalize method?

Thanks and regards,
Rishi.

I''d say don''t implement finalizers; for real resources (open files, sockets etc.)
close them as soon as you''re done with them; don''t delay that to the finalization
stage. If you''re done with a POJO (Plain Old Java Object) you could set its
reference to null a.s.a.p. but don''t use finalizers; as I wrote: they''re a mess.


这篇关于GC循环中Finalize对象的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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