3

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?

1

4 Answers 4

3

I think JConsole would be a good start.

Sign up to request clarification or add additional context in comments.

Comments

1

You could use java.lang.management.MemoryUsage, or the external tool, VisualVM (shipped with JDK).

Comments

1

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;

Comments

0

Is there something that jConsole can't provide? That shows Heap, Classes, Threads, CPU and a heck of a lot more.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.