Java线程和多线程——Thread Dump
Posted EthanPark
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java线程和多线程——Thread Dump相关的知识,希望对你有一定的参考价值。
Java的Thread Dump就是列出JVM中所有激活状态的线程。
Java Thread Dump
Java Thread Dump在分析应用性能瓶颈和死锁的时候,是非常有效的。
下面将介绍多种不同的方式来获取Java程序的Thread Dump信息。这些指令在*nix型的操作系统下是有效的,但是在Windows下面,采取的方式会有一些不同。(主要是Pid信息获取不太一致,可通过任务管理器获取)
- VisualVM Profiler:如果开发者需要分析程序变慢的原因,那么必然要使用profiler。我们可以通过VisulaVM Profiler工具很容易的从运行的线程获取Thread Dump。你所需要的就是右键运行的进行,然后点击Thread Dump来获得这个信息。
- jstack:Java本身就自带的jstack工具,我们可以通过Java线程来直接生成Thread Dump。
- 受限找到Java进程的
PID
,可以通过ps -eaf | grep java
命令来获取。 - 然后运行jstack工具,
jstack PID
来生成Thread Dump到控制台,当然,也可以通过重定向,将Thread Dump信息的输出通过命令jstack PID >> thread.dump
写入thread.dump
这个文本当中。
- 受限找到Java进程的
- 我们可以通过
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
这个文件之中。 - 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会列出全部的线程,每个条目都包含如下的信息:
- Thread Name:线程的名字
- Thread Priority:线程的优先级
- Thread ID:代表线程的ID
- Thread Status:表示线程的状态,举例来说就是RUNNABLE,WAITING,BLOCKED等等,当在分析死锁的时候,可以查看阻塞的线程和被请求的资源。
- Thread CallStack:提供一个线程至关重要的堆栈信息。这也是我们可以看到线程获取的锁和是否在等待锁等信息。
通过上面这些信息,就能够看到一些程序的线程细节,当程序有一些问题之类,就可以从中找到真正影响性能的地方。
以上是关于Java线程和多线程——Thread Dump的主要内容,如果未能解决你的问题,请参考以下文章
如何使用thread dump和分析Thread dump?