使用jvisualvm进行内存采样 [英] Memory sampling with jvisualvm

查看:224
本文介绍了使用jvisualvm进行内存采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java Visual VM的内存采样功能,但无法回答以下问题:

I am using memory sampling feature of Java Visual VM and I can't answer the questions:

  1. 为什么创建了这么多实例?

  1. Why are there so many instances created?

为什么这些实例和字节的数量持续增加?

Why does these numbers of instances and bytes keep increasing?

例如,我创建了一个非常简单的Java程序,如下所示:

For instance, I created a very simple Java program as follow:

public class TestMemory{
    public static void main(String[] args) throws InterruptedException {
        System.out.println("Hello");
        Thread.sleep(60 * 60 * 1000);
    }
} 

我可以在Java Visual VM中看到611个类.实例数一直从25,000增加到接近50,000,然后又回落到25,000左右.实例减少的原因可能是GC引起的,但是我不知道为什么这些数字如此动态,即使我对程序没有做任何事情.

And I can see in Java Visual VM that there are 611 classes. The number of instances keep increasing from 25,000 up to near 50,000 and then fall back to around 25,000. The reason for the decreasing of instances might be caused by GC, but I don't know why those numbers are so dynamic even though I am not doing anything with my program.

推荐答案

您正在查看的实例和字节数是

The number of instances and bytes that you are looking at is the cost of monitoring an app from VisualVM. VisualVM is polling various JVM MBeans, continuously to analyze the value change from your application.

要确认这一点,您可以转到采样器标签.点击每个线程分配子标签.查看繁忙线程是否为RMI TCP Connection(n).该线程应该每秒分配高字节.

To confirm this, you can go to the Sampler tab. Click on the Per thread allocation sub tab. See if the busy thread is RMI TCP Connection(n). This thread should have a high bytes allocation per second.

我也想知道如何优化它,因此发布了更具体的

I was curious on how to optimize this too, hence posting a more specific question.

这篇关于使用jvisualvm进行内存采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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