Java的Thread Dump就是列出JVM中所有激活状态的线程。

Java Thread Dump

Java Thread Dump在分析应用性能瓶颈和死锁的时候,是非常有效的。

下面将介绍多种不同的方式来获取Java程序的Thread Dump信息。这些指令在*nix型的操作系统下是有效的,但是在Windows下面,采取的方式会有一些不同。(主要是Pid信息获取不太一致,可通过任务管理器获取)

  1. VisualVM Profiler:如果开发者需要分析程序变慢的原因,那么必然要使用profiler。我们可以通过VisulaVM Profiler工具很容易的从运行的线程获取Thread Dump。你所需要的就是右键运行的进行,然后点击Thread Dump来获得这个信息。

  2. jstack:Java本身就自带的jstack工具,我们可以通过Java线程来直接生成Thread Dump。
    1. 受限找到Java进程的PID,可以通过ps -eaf | grep java命令来获取。
    2. 然后运行jstack工具,jstack PID来生成Thread Dump到控制台,当然,也可以通过重定向,将Thread Dump信息的输出通过命令jstack PID >> thread.dump写入thread.dump这个文本当中。
  3. 我们可以通过kill -3 PID命令来生成Thread Dump信息。这种方式和其它的生成Thread Dump的方式略有不同,当执行了kill命令的时候,Thread Dump信息会直接输出到控制台。所以,如果Java程序的System.out是控制台的话,Thread Dump的信息就会打印到控制台。如果Java的程序时一个Tomcat的服务程序,System.out将变成catalina.out文件,那时,Thread Dump会打印到catalina.out这个文件之中。
  4. Java 8引入了jcmd工具箱,开发者如果使用的是Java 8或者更高的版本的话,可以用之来替换掉jstack。命令行与jstack很类似:jcmd PID Thread.print

上面的四种方式都可以用来在Java中生成Thread Dump的信息。通常,我推荐使用jstack或者jcmd命令来生成Thread Dump信息来分析。当然,无论你使用什么样的方式,最后的Thread Dump的信息都是一样的。

Java Thread Dump举例

我将自己写的一个Tomcat程序运行Thread Dump,结果如下:

$ jcmd 4428 Thread.print
4428:
2016-09-27 22:42:29
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.65-b01 mixed mode): "ajp-nio-8009-AsyncTimeout" #39 daemon prio=5 os_prio=0 tid=0x000000001d4c4000 nid=0x34c4 waiting on condition [0x000000002ca1f000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at org.apache.coyote.AbstractProtocol$AsyncTimeout.run(AbstractProtocol.java:1080)
at java.lang.Thread.run(Thread.java:745) "ajp-nio-8009-Acceptor-0" #38 daemon prio=5 os_prio=0 tid=0x000000001d4c6800 nid=0x34c0 runnable [0x000000002c91f000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422)
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250)
- locked <0x0000000080b2bfb0> (a java.lang.Object)
at org.apache.tomcat.util.net.NioEndpoint$Acceptor.run(NioEndpoint.java:508)
at java.lang.Thread.run(Thread.java:745) "ajp-nio-8009-ClientPoller-1" #37 daemon prio=5 os_prio=0 tid=0x000000001d4c3800 nid=0x34bc runnable [0x000000002c81e000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x00000000829ecd28> (a sun.nio.ch.Util$2)
- locked <0x00000000829ecd18> (a java.util.Collections$UnmodifiableSet)
- locked <0x00000000829ecba8> (a sun.nio.ch.WindowsSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:843)
at java.lang.Thread.run(Thread.java:745) "ajp-nio-8009-ClientPoller-0" #36 daemon prio=5 os_prio=0 tid=0x000000001d4c5800 nid=0x34b8 runnable [0x000000002b72f000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x00000000829ee720> (a sun.nio.ch.Util$2)
- locked <0x00000000829ee710> (a java.util.Collections$UnmodifiableSet)
- locked <0x00000000829ee5a0> (a sun.nio.ch.WindowsSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:843)
at java.lang.Thread.run(Thread.java:745) "http-nio-8080-AsyncTimeout" #35 daemon prio=5 os_prio=0 tid=0x000000001d4c1000 nid=0x34b4 waiting on condition [0x000000002b62f000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at org.apache.coyote.AbstractProtocol$AsyncTimeout.run(AbstractProtocol.java:1080)
at java.lang.Thread.run(Thread.java:745) "http-nio-8080-Acceptor-0" #34 daemon prio=5 os_prio=0 tid=0x000000001d4c2800 nid=0x34b0 runnable [0x000000002b52f000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422)
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250)
- locked <0x0000000080b30a30> (a java.lang.Object)
at org.apache.tomcat.util.net.NioEndpoint$Acceptor.run(NioEndpoint.java:508)
at java.lang.Thread.run(Thread.java:745) "http-nio-8080-ClientPoller-1" #33 daemon prio=5 os_prio=0 tid=0x000000001d4c2000 nid=0x34ac runnable [0x000000002b1de000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x0000000082896118> (a sun.nio.ch.Util$2)
- locked <0x0000000082896108> (a java.util.Collections$UnmodifiableSet)
- locked <0x0000000082895f98> (a sun.nio.ch.WindowsSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:843)
at java.lang.Thread.run(Thread.java:745) "http-nio-8080-ClientPoller-0" #32 daemon prio=5 os_prio=0 tid=0x000000001d4c0800 nid=0x34a8 runnable [0x000000002b0de000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x0000000082896af8> (a sun.nio.ch.Util$2)
- locked <0x0000000082896ae8> (a java.util.Collections$UnmodifiableSet)
- locked <0x0000000082896978> (a sun.nio.ch.WindowsSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:843)
at java.lang.Thread.run(Thread.java:745) "ContainerBackgroundProcessor[StandardEngine[Catalina]]" #31 daemon prio=5 os_prio=0 tid=0x000000001f3d8800 nid=0x34a4 waiting on condition [0x0000000029fce000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1340)
at java.lang.Thread.run(Thread.java:745) "pool-2-thread-1" #30 prio=5 os_prio=0 tid=0x000000001f3dc800 nid=0x3498 waiting on condition [0x00000000288df000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x0000000082753eb0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
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) "Timer-0" #29 daemon prio=5 os_prio=0 tid=0x000000001f3d6000 nid=0x3494 in Object.wait() [0x000000002856f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.util.TimerThread.mainLoop(Timer.java:552)
- locked <0x0000000082751430> (a java.util.TaskQueue)
at java.util.TimerThread.run(Timer.java:505) "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_QuartzSchedulerThread" #28 prio=5 os_prio=0 tid=0x000000001f3dd000 nid=0x3490 in Object.wait() [0x000000002846e000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:410)
- locked <0x0000000082751b28> (a java.lang.Object) "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-10" #27 prio=5 os_prio=0 tid=0x000000001f3d7800 nid=0x348c in Object.wait() [0x000000002826f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
- locked <0x0000000082717950> (a java.lang.Object) "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-9" #26 prio=5 os_prio=0 tid=0x000000001f3da000 nid=0x3488 in Object.wait() [0x000000002816f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
- locked <0x0000000082717618> (a java.lang.Object) "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-8" #25 prio=5 os_prio=0 tid=0x000000001f3db800 nid=0x3484 in Object.wait() [0x000000002806f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
- locked <0x00000000827172e0> (a java.lang.Object) "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-7" #24 prio=5 os_prio=0 tid=0x000000001f3d9000 nid=0x3480 in Object.wait() [0x0000000027f6f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
- locked <0x0000000082716fa8> (a java.lang.Object) "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-6" #23 prio=5 os_prio=0 tid=0x000000001f3db000 nid=0x347c in Object.wait() [0x0000000027e6e000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
- locked <0x0000000082716c70> (a java.lang.Object) "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-5" #22 prio=5 os_prio=0 tid=0x000000001f3d7000 nid=0x3478 in Object.wait() [0x0000000027d6f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
- locked <0x0000000082716938> (a java.lang.Object) "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-4" #21 prio=5 os_prio=0 tid=0x000000002107b800 nid=0x3474 in Object.wait() [0x0000000027c6f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
- locked <0x0000000082716600> (a java.lang.Object) "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-3" #20 prio=5 os_prio=0 tid=0x0000000023019000 nid=0x3470 in Object.wait() [0x0000000027b6f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
- locked <0x000000008270fb40> (a java.lang.Object) "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-2" #19 prio=5 os_prio=0 tid=0x000000001f6a4000 nid=0x346c in Object.wait() [0x000000002721f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
- locked <0x00000000827162b0> (a java.lang.Object) "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1" #18 prio=5 os_prio=0 tid=0x000000001a75a800 nid=0x3468 in Object.wait() [0x000000002014f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
- locked <0x0000000082715f78> (a java.lang.Object) "NioBlockingSelector.BlockPoller-2" #15 daemon prio=5 os_prio=0 tid=0x0000000019d0b000 nid=0x2150 runnable [0x000000001b59e000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x0000000080a8c5c8> (a sun.nio.ch.Util$2)
- locked <0x0000000080a8c5b8> (a java.util.Collections$UnmodifiableSet)
- locked <0x0000000080a8c448> (a sun.nio.ch.WindowsSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at org.apache.tomcat.util.net.NioBlockingSelector$BlockPoller.run(NioBlockingSelector.java:341) "NioBlockingSelector.BlockPoller-1" #14 daemon prio=5 os_prio=0 tid=0x0000000019d09000 nid=0x890 runnable [0x000000001b49f000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x0000000080b2d2f8> (a sun.nio.ch.Util$2)
- locked <0x0000000080b2d2e8> (a java.util.Collections$UnmodifiableSet)
- locked <0x0000000080b2d188> (a sun.nio.ch.WindowsSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at org.apache.tomcat.util.net.NioBlockingSelector$BlockPoller.run(NioBlockingSelector.java:341) "GC Daemon" #13 daemon prio=2 os_prio=-2 tid=0x0000000019e8d800 nid=0x27fc in Object.wait() [0x000000001b17f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x0000000080c322d0> (a sun.misc.GC$LatencyLock)
at sun.misc.GC$Daemon.run(GC.java:117)
- locked <0x0000000080c322d0> (a sun.misc.GC$LatencyLock) "Service Thread" #11 daemon prio=9 os_prio=0 tid=0x0000000018c19000 nid=0x2a78 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE "C1 CompilerThread2" #10 daemon prio=9 os_prio=2 tid=0x0000000018bc2800 nid=0x11b8 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE "C2 CompilerThread1" #9 daemon prio=9 os_prio=2 tid=0x0000000018bc1800 nid=0x1f90 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE "C2 CompilerThread0" #8 daemon prio=9 os_prio=2 tid=0x0000000018bbf800 nid=0x3288 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE "JDWP Event Helper Thread" #7 daemon prio=10 os_prio=0 tid=0x0000000018bb2800 nid=0x339c runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE "JDWP Transport Listener: dt_socket" #6 daemon prio=10 os_prio=0 tid=0x0000000018ba6800 nid=0x1628 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE "Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x00000000175cd800 nid=0x1790 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE "Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x000000001761e000 nid=0xa24 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE "Finalizer" #3 daemon prio=8 os_prio=1 tid=0x0000000002998000 nid=0xb94 in Object.wait() [0x000000001893f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
- locked <0x000000008051aa40> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209) "Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x000000000298f000 nid=0x5cc in Object.wait() [0x000000001883f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:157)
- locked <0x00000000800cce68> (a java.lang.ref.Reference$Lock) "main" #1 prio=5 os_prio=0 tid=0x000000000240e000 nid=0x2478 runnable [0x000000000289e000]
java.lang.Thread.State: RUNNABLE
at java.net.DualStackPlainSocketImpl.accept0(Native Method)
at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)
- locked <0x0000000082a8afe0> (a java.net.SocksSocketImpl)
at java.net.ServerSocket.implAccept(ServerSocket.java:545)
at java.net.ServerSocket.accept(ServerSocket.java:513)
at org.apache.catalina.core.StandardServer.await(StandardServer.java:446)
at org.apache.catalina.startup.Catalina.await(Catalina.java:737)
at org.apache.catalina.startup.Catalina.start(Catalina.java:683)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485) "VM Thread" os_prio=2 tid=0x0000000017587000 nid=0x1aec runnable "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00000000028b7000 nid=0x1ea0 runnable "GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00000000028b8800 nid=0x19ac runnable "GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00000000028ba000 nid=0x2de8 runnable "GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00000000028bd000 nid=0x540 runnable "VM Periodic Task Thread" os_prio=2 tid=0x0000000018c46000 nid=0x240c waiting on condition JNI global references: 6164

Thread Dump会列出全部的线程,每个条目都包含如下的信息:

  1. Thread Name:线程的名字
  2. Thread Priority:线程的优先级
  3. Thread ID:代表线程的ID
  4. Thread Status:表示线程的状态,举例来说就是RUNNABLE,WAITING,BLOCKED等等,当在分析死锁的时候,可以查看阻塞的线程和被请求的资源。
  5. Thread CallStack:提供一个线程至关重要的堆栈信息。这也是我们可以看到线程获取的锁和是否在等待锁等信息。

通过上面这些信息,就能够看到一些程序的线程细节,当程序有一些问题之类,就可以从中找到真正影响性能的地方。

Java线程和多线程(八)——Thread Dump的更多相关文章

  1. Java线程与多线程教程

    本文由 ImportNew - liken 翻译自 Journaldev.   Java线程是执行某些任务的轻量级进程.Java通过Thread类提供多线程支持,应用可以创建并发执行的多个线程. 应用 ...

  2. Java线程和多线程(九)——死锁

    Java中的死锁指的就是一种多于两个线程永远阻塞的特殊状况.Java中的死锁状态至少需要多于两个线程以及资源的时候才会产生.这里,我写了一个产生死锁的程序,并且讲下如何分析死锁. 首先来看一下产生死锁 ...

  3. 【转】java线程系列---Runnable和Thread的区别

    在java中可有两种方式实现多线程,一种是继承Thread类,一种是实现Runnable接口:Thread类是在java.lang包中定义的.一个类只要继承了Thread类同时覆写了本类中的run() ...

  4. Java 线程和多线程执行过程分析

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...

  5. Java线程和多线程(十三)——Callable,Future,FutureTask

    在Java多线程之中,Callable和Future的使用时非常广泛的.在之前的文章中,我们了解了关于Java线程池基础的一些内容,知道如何提交Runnable的任务.但是,Runnable的任务是无 ...

  6. Java线程和多线程(十二)——线程池基础

    Java 线程池管理多个工作线程,其中包含了一个队列,包含着所有等待被执行的任务.开发者可以通过使用ThreadPoolExecutor来在Java中创建线程池. 线程池是Java中多线程的一个重要概 ...

  7. Java线程详细监控和其dump的分析使用—-分析Java性能瓶颈

    转载:https://www.cnblogs.com/firstdream/p/8109352.html 这里对linux下.sun(oracle) JDK的线程资源占用问题的查找步骤做一个小结: l ...

  8. Java线程和多线程(三)——线程安全和同步

    线程安全在Java中是一个很重要的课题.Java提供的多线程环境支持使用Java线程.我们都知道多线程共享一些对象实例的话,可能会在读取和更新共享数据的事后产生数据不一致问题. 线程安全 之所以会产生 ...

  9. Java线程和多线程(一)——线程的基本概念

    Java 线程是一个轻量级执行任务的处理单元.Java提供了Thread类来支持多线程,开发者在应用中可以创建多个线程来支持并发执行任务. 在应用中存在两种类型的线程,用户线程和守护线程.当我们启动应 ...

随机推荐

  1. react-native与原生界面相互跳转

    一.添加MyIntentModule类,并继承ReactContextBaseJavaModule实现其方法和构造函数.在该类中添加方法,注意:方法头要加@ReactMethod public cla ...

  2. arm寄存器解析

    寒假闲来无事准备将自己的走过的arm之路总结一下,今天就先从arm的寄存器说起吧,欢迎各位拍砖. 要介绍arm寄存器之前我们要先了解一下arm处理器的工作模式: Arm处理器有七种工作模式,为的是形成 ...

  3. JUnit4 学习笔记

    一.环境搭建: 1.需要用的包: JUnit4.7:http://files.cnblogs.com/files/ShawnYang/junit4.7.zip hamcrest-1.2:http:// ...

  4. centreon-engine 性能调优

    http://documentation.centreon.com/docs/centreon-engine/en/latest/user/configuration/best_practice.ht ...

  5. 简单粗暴的更换固态硬盘及WIN10 Ubuntu双系统

    简介:本文希望帮助如本人一样的计算机小白,能够以最快的速度更换固态硬盘及安装系统. 1.提前将准备空白U盘(至少8G),利用UltraISO工具,或者软媒魔方,制作U盘启动盘. PS:需提前下载好WI ...

  6. ui.datepicker的回显问题

    应用场景: 页面上有一些现有的输入框,需要调用日期插件,同时还要clone一份,动态添加到页面中,动态生成的输入框在调用datepicker的时候,click事件有效,但是选择的时间无法回显到对应的输 ...

  7. ASP.NET Core - 初期准备

    微软在前不久发布了.NET Core1.0(以下简称Core),由于项目需要开始对其进行研究,希望将自己踩过的坑和见解分享给大家. Core和Framework4.6是属于并行产品,前者侧重于跨平台的 ...

  8. 在vue中使用animate库

    <style> @keyframes bounce-in { 0% { transform: scale(0); } 50% { transform: scale(1.5) } 100% ...

  9. Spring Security 之Session管理配置

    废话不多说,直接上代码.示例如下: 1.   新建Maven项目  session 2.   pom.xml <project xmlns="http://maven.apache.o ...

  10. Integer和int使用==比较的总结

    public static void main(String[] args) { int i1 = 128; Integer i2 = 128; Integer i3 = new Integer(12 ...