How to check memory usage by java program?

Is there any native Java code to check the memory used by the program, or is the only way to check the memory used by the itlself JVM?
can this be done exclusively in java or do we need an external process to do this work?

+3
source share
4 answers

I think JConsole would be a good start.

+4
source

You can use java.lang.management.MemoryUsageeither the external VisualVM tool (supplied with the JDK).

+1
source

java.lang.management.MemoryMXBean , MemoryUsage. , , :

MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
long heapMemUsed = memoryBean.getHeapMemoryUsage().getUsed();
long otherMemUsed = memoryBean.getNonHeapMemoryUsage().getUsed();
long totalMemoryUsed = heapMemUsed + otherMemUsed;
+1
source

Is there something that jConsole cannot provide? It shows heaps, classes, threads, processor, and more.

0
source

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


All Articles