java服务端程序报错后会生成hprof文件,我们可以通过mat工具MemoryAnalyzer进行分析
下载地址:
http://www.eclipse.org/mat/downloads.php
说明:
查看HPROF快照
JProfiler能打开用JVM工具(比如jconsole、 jmap或通过-XX:+HeapDumpOnOutOfMemoryError JVM参数触发)创建的HPROF快照文件
示例:
#!/bin/bash
LANG="zh_CN.UTF-8" APP_HOME=$(echo `pwd` | sed 's/bin//')
APPPIDFILE=$APP_HOME/app.pid case $1 in
start)
echo "Starting server... " HEAP_MEMORY=512m
PERM_MEMORY=64m
JMX_PORT=8888
JMX_HOST=1.1.1.1
JAVA_OPTS="-server -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.EPollSelectorProvider -XX:+HeapDumpOnOutOfMemoryError -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false " shift
ARGS=($*)
for ((i=0; i<${#ARGS[@]}; i++)); do
case "${ARGS[$i]}" in
-D*) JAVA_OPTS="${JAVA_OPTS} ${ARGS[$i]}" ;;
-Heap*) HEAP_MEMORY="${ARGS[$i+1]}" ;;
-Perm*) PERM_MEMORY="${ARGS[$i+1]}" ;;
-JmxPort*) JMX_PORT="${ARGS[$i+1]}" ;;
-JmxHost*) JMX_HOST = "${ARGS[$i+1]}" ;;
esac
done
JAVA_OPTS="${JAVA_OPTS} -Xms${HEAP_MEMORY} -Xmx${HEAP_MEMORY} -XX:PermSize=${PERM_MEMORY} -XX:MaxPermSize=${PERM_MEMORY} -Dcom.sun.management.jmxremote.port=${JMX_PORT} -Djava.rmi.server.hostname=${JMX_HOST} -Dapp.home=${APP_HOME}"
echo "start jvm args ${JAVA_OPTS}"
nohup java -classpath .:./aa-media-2.0.0.jar:$CLASSPATH $JAVA_OPTS com.aaa.media.aaaMediaServer&
echo $! > $APPPIDFILE
echo STARTED
;; stop)
echo "Stopping server ... "
if [ ! -f $APPPIDFILE ]
then
echo "error: count not find file $APPPIDFILE"
exit 1
else
kill -15 $(cat $APPPIDFILE)
rm $APPPIDFILE
echo STOPPED
fi
;; *)
echo "Please enter start|stop ... "
;; esac exit 0