Java線程問題分析定位

Java線程問題分析定位java

分析步驟:ui

一、使用top命令查看系統資源佔用狀況,發現Java進程佔用大量CPU資源,PID爲11572;spa

二、顯示進程詳細列表命令:ps -mp 11572 -o THREAD,tid,time線程

找到消耗資源多的TID,如TID:112052日誌

 三、將TID轉換成16進制:printf "%x\n" 12052進程

 

四、打印堆棧信息:jstack 11572 |grep 2f14 -A 30ci

 

Thread dump信息以下:資源

"thread1" prio=6 tid=0x02de8400 nid=0x2688 runnable [0x0320f000]it

   java.lang.Thread.State: RUNNABLEio

    at DeadLock.callLongTime(DeadLock.java:63)

    at DeadLock$2.run(DeadLock.java:41)

    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)

    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)

    at java.util.concurrent.FutureTask.run(FutureTask.java:166)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

    at java.lang.Thread.run(Thread.java:722)

 

   Locked ownable synchronizers:

    - <0x22be1488> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)

 

"thread2" prio=6 tid=0x02de6c00 nid=0x218c waiting on condition [0x031bf000]

   java.lang.Thread.State: WAITING (parking)

    at sun.misc.Unsafe.park(Native Method)

    - parking to wait for  <0x22be1488> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)

    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)

    at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:834)

    at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:867)

    at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1197)

    at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:214)

    at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:290)

    at DeadLock$2.run(DeadLock.java:40)

    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)

    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)

    at java.util.concurrent.FutureTask.run(FutureTask.java:166)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

    at java.lang.Thread.run(Thread.java:722)

 

   Locked ownable synchronizers:

    - <0x22be64e0> (a java.util.concurrent.ThreadPoolExecutor$Worker)

 

          線程「thread2」處於WAITING狀態,- parking to wait for  <0x22be1488>,等待給0x22be1488的地址,而0x22be1488地址正被「thread1」上鎖,Dump日誌中有大量線程等待給這個地址上鎖,就會出現線程等待資源超時。

相關文章
相關標籤/搜索