1

I'm having real trouble understanding how to monitoring of JVMs heap usage is supposed to work. I've read multiple threads and they all use the same pattern, taken from this source: https://docs.oracle.com/javase/7/docs/api/java/lang/management/MemoryPoolMXBean.html

However, the listener never seams to fire an event. I just want to be able to display the current heap size of JVM in real time INSIDE my GUI. How can I do that?

1
  • 1
    From within the JVM process that's running, or from an external program? Where is your code? Commented Dec 6, 2016 at 17:57

2 Answers 2

2

Jvisualvm tool is what you need, it's in the bin repository of your jdk, search for jvisualvm.exe and launch it, you can check your heap and permgen memories in realtime.

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

3 Comments

Well I'd like to display it inside my GUI in a JTextArea :/
@Zorobay Then you're looking for Runtime.getRuntime().freeMemory() and Runtime.getRuntime().totalMemory()
If you want to display it inside a GUI I think this post can help : stackoverflow.com/questions/17364820/… this way you can invoke jvisualvm from your GUI
1

You don't need JMX for this use case.

 Runtime.getRuntime().totalMemory(); 

... and similar methods in Runtime , give you instantaneous memory info. Set a scheduler to do this and update your GUI.

Of course, JMX is valuable if you want to monitor this kind of thing externally.

2 Comments

I might use this, thanks. Still, it is not as optimized as just listening for a change...:(
and if you wanna generate a graph out of this. Poll this in a loop and u will have required info to generate graph

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.