快速定位JVM中消耗CPU最多的线程

以cassandra举例,先切换到cassandra用户,然后进行操作。演示截图为测试服务器中任意挑选了一个线程。

1.获取进程ID ,ID为30722

    ps -ef| grep cassandra | grep -v grep

501      30722     1  0 May13 ?        21:27:03 java -ea -javaagent:/home/cassandra/apache-cassandra/bin/../l

2.获取该进程最消耗cpu的thread

    top -Hp 30722

    

3.将线程ID转换成十六进制

    printf '%x\n' 30810

    785a

4.抓取堆栈

    jstack pid

"metrics-meter-tick-thread-2" #15 daemon prio=5 os_prio=0 tid=0x00007f941806f800 nid=0x785a waiting on condition [0x00007f941dd6a000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000000f6af3d78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
        at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1088)
        at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
        at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

 

线程栈中 nid 的值,其实就是线程 ID(十进制)转换十六进制后的值

posted on 2018-09-07 15:34  明.Sir  阅读(586)  评论(0编辑  收藏  举报

导航