Find the maximum allocated heap size at runtime using the VM command line?

I wonder if I can get the maximum allocated heap size using the VM command line.

Now I can get it using Netbeans Profiler , but I prefer to get the result without having to run an additional application.

I also use this method:

 public void printMemUsage(){ double currentMemory = ( (double)((double)(Runtime.getRuntime().totalMemory()/1024.0)))- ((double)((double)(Runtime.getRuntime().freeMemory()/1024.0))); System.out.println("Current memory usage in kilobytes :"+currentMemory); } 

I think I can use this to get the maximum heap size, but I'm not sure if it is very reliable.

I am currently using these command lines:

-verbose: gc -XX: + PrintGCDetails -XX: + PrintGCApplicationConcurrentTime -XX: + PrintGCApplicationStoppedTime

To get good information about the activities of gc, the young generation, the old and the constant. But I can just tell the current full heap space when the collection occurs.

So, is there a way to get the maximum heap space that has been allocated using other commands?

+4
source share
1 answer

You must use MemoryMXBean , see javadoc to learn how to use it to get information about each MemoryPool (aka generation) and to be notified when different events occur.

+2
source

Source: https://habr.com/ru/post/1394894/


All Articles