Reputation: 787
Is there any native java code to check the memory utilized by the program, or the only way possible is to check memory utilized by the JVM itlself?
can this be done purely in java or we need external process to fulfill this job?
Upvotes: 3
Views: 1201
Reputation: 1537
I personally find java.lang.management.MemoryMXBean
to be simpler to use than MemoryUsage
. You can get the memory used by the program as follows:
MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
long heapMemUsed = memoryBean.getHeapMemoryUsage().getUsed();
long otherMemUsed = memoryBean.getNonHeapMemoryUsage().getUsed();
long totalMemoryUsed = heapMemUsed + otherMemUsed;
Upvotes: 1
Reputation: 38836
You could use java.lang.management.MemoryUsage
, or the external tool, VisualVM (shipped with JDK).
Upvotes: 1
Reputation: 2924
Is there something that jConsole can't provide? That shows Heap, Classes, Threads, CPU and a heck of a lot more.
Upvotes: 0