Java

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}

Linux
CTRL+C if JVM is the foreground process
kill -3 <pid>

Free memory on Linux
vmstat -s
free -m

Enable verbose GC
verbose:gc –XX:+PrintGCDetails –XX:+PrintGCTimeStamps –Xloggc:<app path>/gc.log

Get JVM flag information
jinfo.exe -flag <flagName> <pid>

e.g., to check the value of -XX:PermSize JVM option run
jinfo -flag PermSize <pid>

How to get memory usage of tomcat 7 using JMX API?
http://stackoverflow.com/questions/9206002/how-to-get-memory-usage-of-tomcat-7-using-jmx-api

Where to set java heap options (e.g. -Xmx) for Tomcat 6 under Ubuntu 9.04
The most elegant way I’ve found so far is to edit /etc/init.d/tomcat6 and add this at the top of the file:
# local config settings
JAVA_OPTS=”-Xms5000m -Xmx13000m
http://serverfault.com/questions/139435/where-to-set-java-heap-options-e-g-xmx-for-tomcat-6-under-ubuntu-9-04

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s