Ever suspect your Java app leaking memory but not sure which class it is potentially causing OOM?
In this post, I recommend Eclipse Memory Analyzer (MAT) for developers to analyze heap dumps so you can chase down leak suspects. MAT is much easier to use and read than stand-along jhat unix command, and while monitor memory usage using VisualVM is helpful, MAT gives you specific hints about which classes may be the suspects.
It is not uncommon that you need to watch the runtime performance of a Java application on a server. In this post, I'll show you how to set up a target JVM so you can monitor its cpu, heap memory, threads usage from a specific JMX client - VisualVM. VisualVM is similar to JConsole, a JMX-compliant monitoring tool, but is more advanced.
To use a JMX client, the setup you need to do first are:
Enable JMX Agent for JVM
With JMX agent enabled for a JVM, you can use a JMX Client (JConsole or VisualVM) to tap into your JVM to monitor its performance and memory usage at runtime. Your java runtime is not enabled with JMX by default unless you explicitly specify to turn it on.
Before I go into WeakHashmap, first let's look at different types of reference-object. A reference object encapsulates a reference to some other object. There are different level of reachability of references, from the strongest to the weakest. The weaker the reference, the more likely it is to be thrown away.