我怎么知道谁调用了System.gc()? [英] How can I tell who calls System.gc()?

查看:171
本文介绍了我怎么知道谁调用了System.gc()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个正在运行的系统中,我们看到很多Full GC(System),表示有人触发System.gc()。

有没有一种方法可以找到

我搜索了所有可用的源代码,但没有发现任何可疑内容,因此它必须位于某处,可能是另一个运行在同一个容器中的应用程序,或者容器本身。

解决方案

您可以更改Runtime类以记录gc()被调用到文件的位置(System。 gc()调用Runtime.gc())

为此,编辑一个副本,将其编译并添加到 -Xbootclasspath / p :



然而,大量的Full GC更可能是由于生存空间不足或完全的终身空间造成的。



你可以试试跑吗?

  jstat -gccause {pid} 5s 


In a running system, we see lots of "Full GC (System)" which indicates someone triggers System.gc().

Is there a way to find out where in the code this happens?

I did search all the available source but found nothing suspicious so it must be somewhere, probably another app that's running in the same container or the container itself.

解决方案

You can change the Runtime class to log where gc() is being called to a file (System.gc() calls Runtime.gc())

To do this, edit a copy, compile it and add it to your -Xbootclasspath/p:

However a high number of Full GC is more likely to be due to insufficient survivor space or a full tenured space.

Can you try running

jstat -gccause {pid} 5s 

这篇关于我怎么知道谁调用了System.gc()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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