In JDK 1.4.x monitoring the JVMs memory usage was an arduous task requiring a special unsupported JVM. I’d heard JDK 1.5 had improved support but I haven’t had a reason to look at it until this week. It was a nice surprise to see how easy it is to enable monitoring:
1. Add -Dcom.sun.management.jmxremote to your java command line (and start your process).
2. Start [java 1.5]\jdk\bin\jconsole. Your done.
>java -version java version "1.5.0_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05) Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode) >java -Dcom.sun.management.jmxremote SoapDemo >jps 2672 SoapDemo 3784 Jps >jconsole 2672
In this example we check the jvm version is 1.5 or greater, enable the JMX agent, and launch jconsole with the correct proccess id (2672). The console monitors the process and allows you to track memory usage in all generations of the JVM Heap,
Thread State and you can also enable/disable verbose gc dynamically.
A more detailed overview of jconsole can be found here.