root@ubuntu-B85M-D3H:~/tmp# cat java_Analy.shjava
#!/bin/bashubuntu
T=`ps -mp $1 -o THREAD,tid,time|sort -k 2 -nr|awk '{print $2","$8","$9}'|head -n 11|grep -v "-"`bash
for i in $T
do
consum=`echo $i |awk -F"," '{print $1}'`
tid=`echo $i |awk -F"," '{print $2}'`
dtime=`echo $i |awk -F"," '{print $3}'`
id=`printf "%x\n" $tid`
echo "線程消耗CPU:$consum% 運行時間:$dtime 線程id:$id" >>Analy.txt
jstack $1 |grep $id -A 30 >>Analy.txt
echo "">>Analy.txt
echo "===========================================================================================" >>Analy.txt.net
done線程
使用說明:先使用top查詢出佔用cpu高的java程序的pid,而後執行./java_Analy.sh pid 以後把生成的Analy.txt文件交給開發就好了blog
參考連接:http://blog.csdn.net/blade2001/article/details/9065985開發