JVM实战学习——排查java程序 死锁(jstack)

JVM实战学习——排查java程序 磁盘IO占用过高、CPU占用过高、内存占用过高(pidstat)

一、排查cpu高占用

1.示例代码

使用以下代码,启动的服务会产生cpu资源大量占用的情况
1)死锁程序
2)启动类

2.查询项目进程

1)使用 jps 命令查询项目启动的进程
[root]# jps -l
22640 study-java-jvm-app-1.0-SNAPSHOT.jar   ## 其中 22640 就是项目进程
1349 -- process information unavailable
22714 sun.tools.jps.Jps
2)或者使用 ps -ef | grep java 同样可以查询进程号
[root]# ps -ef | grep java
##   其中 22640 就是项目进程
root     22640 17949  9 09:57 pts/0    00:00:06 java -jar study-java-jvm-app-1.0-SNAPSHOT.jar
root     22871 21072  0 09:58 pts/1    00:00:00 grep java

3.使用 jstack 工具导出堆栈信息,并进行死锁检测

## -l 死锁检测,输出找到的死锁信息
## 22640 即进程号
## > jstack.text 将堆栈信息导出到文件

[root]# jstack -l 22640 > jstack.text

## 死锁的堆栈信息如下所示:
## 根据堆栈信息可以找到对应的代码
## at c_6_3_6.DeadLock$CatThread.run(DeadLock.java:56)
## at c_6_3_6.DeadLock$DogThread.run(DeadLock.java:31)

Found one Java-level deadlock:
=============================
"Thread-3":
  waiting for ownable synchronizer 0x00000000e31412e0, (a java.util.concurrent.locks.ReentrantLock$NonfairSync),
  which is held by "Thread-2"
"Thread-2":
  waiting for ownable synchronizer 0x00000000e31412b0, (a java.util.concurrent.locks.ReentrantLock$NonfairSync),
  which is held by "Thread-3"

Java stack information for the threads listed above:
===================================================
"Thread-3":
	at sun.misc.Unsafe.park(Native Method)
	- parking to wait for  <0x00000000e31412e0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
	at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireInterruptibly(AbstractQueuedSynchronizer.java:897)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1222)
	at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:335)
	at c_6_3_6.DeadLock$CatThread.run(DeadLock.java:56)
"Thread-2":
	at sun.misc.Unsafe.park(Native Method)
	- parking to wait for  <0x00000000e31412b0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
	at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireInterruptibly(AbstractQueuedSynchronizer.java:897)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1222)
	at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:335)
	at c_6_3_6.DeadLock$DogThread.run(DeadLock.java:31)

Found 1 deadlock.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值