什么是“执行GC”按钮做在jconsole? [英] What does "Perform GC" button do in jconsole?

查看:226
本文介绍了什么是“执行GC”按钮做在jconsole?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jconsole中有一个按钮Perform GC,任何人都知道如果点击该按钮会发生什么,它调用 System.gc()

解决方案

你可以自己找出答案。 JConsole的代码是OpenJDK的一部分。
您也可以在 grepcode.com

按钮调用 gc()实现 MemoryMXBean 的对象的方法,这很可能通过 com.sun.management .MemoryImpl 类。这个类包含一个 gc()方法的实现,如下所示:

  public void gc(){
Runtime.getRuntime()。gc();

$ / code>

现在,如果考虑执行 gc( )方法在 java.lang.System 看起来像这样:

  public void gc(){
Runtime.getRuntime()。gc();
}

您的问题的答案是:技术上不行,但它确实同样的事情。


There is a button "Perform GC" in jconsole, anyone knows what exactly happens if I click that button, it's invoking System.gc()?

解决方案

You can find out by yourself. The code of JConsole is part of OpenJDK. You can also check it out on grepcode.com.

The button calls a gc() method of an object implementing MemoryMXBean which is most probably implemented by com.sun.management.MemoryImpl class. This class contains an implementation of gc() method which looks like this:

public void gc() {
    Runtime.getRuntime().gc();
}

Now, if you consider the implementation of gc() method in java.lang.System which looks like this:

public void gc() {
    Runtime.getRuntime().gc();
}

the answer to your question is: Technically no, but it does the same thing.

这篇关于什么是“执行GC”按钮做在jconsole?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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