Memory sampling with jvisualvm
Asked Answered
H

1

3

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

  1. Why are there so many instances created?

  2. Why does these numbers of instances and bytes keep increasing?

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);
    }
} 

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.

Handedness answered 21/1, 2013 at 4:15 Comment(0)
C
7

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.

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.

Checker answered 11/6, 2013 at 0:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.