监控线程的3种方法

1. JDK命令行工具 - jstack

jps -l

查询当前运行线程

barry@Y430P:~/data/projects/test$ jps -l
18339 /usr/share/dbeaver//plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar
9046 org.jetbrains.jps.cmdline.Launcher
16087 com.intellij.idea.Main
9049 test.threadjava.ThreadGroupTest
9131 sun.tools.jps.Jps
27133 org.jetbrains.jps.cmdline.Launcher
6606 org.jetbrains.plugins.scala.nailgun.NailgunRunner

jstack -[operation] pid

其中operation:

-F:当 jstack pid没有响应时,使用-F强制dump线程信息

-m:打印java线程栈和本地线程栈

-l:长期监听

barry@Y430P:~/data/projects/test$ jstack 9049
2019-01-02 16:33:25
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.171-b11 mixed mode):

"Attach Listener" #17 daemon prio=9 os_prio=0 tid=0x00007f03fc001000 nid=0x23e3 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"DestroyJavaVM" #16 prio=5 os_prio=0 tid=0x00007f044c00e000 nid=0x235c waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Thread 4" #15 prio=5 os_prio=0 tid=0x00007f044c4a0800 nid=0x2388 waiting on condition [0x00007f0411c36000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep(Native Method)
        at test.threadjava.ThreadGroupTest.run(ThreadGroupTest.java:18)
        at java.lang.Thread.run(Thread.java:748)

"Thread 3" #14 prio=5 os_prio=0 tid=0x00007f044c49f000 nid=0x2387 waiting on condition [0x00007f0411d37000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep(Native Method)
        at test.threadjava.ThreadGroupTest.run(ThreadGroupTest.java:18)
        at java.lang.Thread.run(Thread.java:748)

"Thread 2" #13 prio=5 os_prio=0 tid=0x00007f044c49d000 nid=0x2386 waiting on condition [0x00007f0411e38000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep(Native Method)
        at test.threadjava.ThreadGroupTest.run(ThreadGroupTest.java:18)
        at java.lang.Thread.run(Thread.java:748)

"Thread 1" #12 prio=5 os_prio=0 tid=0x00007f044c49b800 nid=0x2385 waiting on condition [0x00007f0411f39000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep(Native Method)
        at test.threadjava.ThreadGroupTest.run(ThreadGroupTest.java:18)
        at java.lang.Thread.run(Thread.java:748)

"Thread 0" #11 prio=5 os_prio=0 tid=0x00007f044c49a000 nid=0x2384 waiting on condition [0x00007f041203a000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep(Native Method)
        at test.threadjava.ThreadGroupTest.run(ThreadGroupTest.java:18)
        at java.lang.Thread.run(Thread.java:748)

"Service Thread" #10 daemon prio=9 os_prio=0 tid=0x00007f044c476800 nid=0x2382 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C1 CompilerThread3" #9 daemon prio=9 os_prio=0 tid=0x00007f044c461800 nid=0x2381 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread2" #8 daemon prio=9 os_prio=0 tid=0x00007f044c45f800 nid=0x2380 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" #7 daemon prio=9 os_prio=0 tid=0x00007f044c45d000 nid=0x237f waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #6 daemon prio=9 os_prio=0 tid=0x00007f044c45b800 nid=0x237e waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Monitor Ctrl-Break" #5 daemon prio=5 os_prio=
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值