---
title: "GC 问题知识点收录"
author: "dikar"
date: "2012-04-28T16:23:03Z"
tags: []
categories: ["开源软件"]
slug: "gc"
draft: false
lastmod: "2013-08-31T22:23:21Z"
id: 1503756
url: "https://dikar.iteye.com/blog/1503756"
---

经常遇到各种GC造成的小问题干扰，不搞清楚细节就很烦，所以开始一点点收集信息便于以后排查问题。

 

1：gc log中显示 Full GC (System) 字样是什么意思。

 

具体可见下面这篇文章

[http://stackoverflow.com/questions/6626680/does-java-garbage-collection-log-entry-full-gc-system-mean-some-class-called](http://stackoverflow.com/questions/6626680/does-java-garbage-collection-log-entry-full-gc-system-mean-some-class-called)

 

总结下就是 调用了System.gc()后打印的FullGC log

 

2：如何查看谁调用了System.gc()

这个可以使用Btrace 中的jstack功能，代码如下

 

```
import static com.sun.btrace.BTraceUtils.*;
import com.sun.btrace.annotations.*;

@BTrace
public class Js{
   @OnMethod(
      clazz="java.lang.System",
      method="gc"
   )
   public static void traceExecute(){
     println("System.gc() call ---------------------");
     jstack();
   }
}
```

 

 

3:Full GC(System) 有规律的一分钟一次

这个可能是由于rmi的默认gc策略导致的，见[http://docs.oracle.com/javase/1.4.2/docs/guide/rmi/sunrmiproperties.html](http://docs.oracle.com/javase/1.4.2/docs/guide/rmi/sunrmiproperties.html)

**`sun.rmi.dgc.server.gcInterval`**  (1.2 and later) 

**`sun.rmi.dgc.client.gcInterval`** (1.2 and later)

The default value is 60000 milliseconds (60 seconds).

可以手动添加这个参数到JVM启动中，例如修改为默认一天或者一小时GC一次，不建议直接增加DisableExplicitGC

具体原因可以参见撒迦同学的参数陷阱贴

[http://hllvm.group.iteye.com/group/topic/27945](http://hllvm.group.iteye.com/group/topic/27945)  （强力推荐哇![](/images/smiles/icon_biggrin.gif)可以学习到很多知识）

 

4：如何分析CMS gc log

https://blogs.oracle.com/poonam/entry/understanding\_cms\_gc\_logs

 

5：usr  sys real 3者的大概含义

http://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1

6：Diagnosing a Garbage Collection problem

http://www.oracle.com/technetwork/java/example-141412.html