Categories

My learnings about Java as I explore it

Monitoring Java App

Getting head dump
2 ways:
1. Use jmap (which is also part of the Sun JDK 6) to dump the heap of a running application to a file using a command line like
jmap -dump:format=b,file=myheap.hprof <pid>

2. Tell the VM to make a heap dump when an OutOfMemoryException occurs by adding:
-XX:+HeapDumpOnOutOfMemoryError
to the VM parameters at startup. With another switch you can specify the path for the dumps:
-XX:HeapDumpPath=<path/to/dump/file>

Analyzing heap dump
1. Supplying jhat the hprof-file you can point your browser to the integrated web server of jhat and browse the heap looking for the objects that take up your memory.
2. MAT – Memory Analyzer tool

Getting thread dump
Thread dump is stack traces for each thread in the JVM output to stdout as text
Windows
CTRL+BREAK if JVM is the foreground process
jstack {pid}