码迷,mamicode.com
首页 > 编程语言 > 详细

使用线程转储研究运行时的应用程序

时间:2015-05-13 21:39:35      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:

性能分析工具运行程序需要在jvm调试模式下启动,这对实际已经在用的生产应用并不适合;

还好,可以让JVM产生一个完全的线程转储,它可以显示所有线程的状态和调用堆栈;

Unix系统上了可以执行kill -3 <PID>来得到;

Windows系统按组合键Ctrl+Break;

执行命令并不会杀掉java进程;

这里以window为例,一按快捷键,刷刷刷:

技术分享

more:

技术分享
F:\360\workspacemy\CovertJava\srcbin>java covertjava.chat.ChatApplication

Initializing the chat server...

Trying to get the registry on port 1149

Registry was not running, trying to create one...

ChatApplication server initialized

2015-05-12 10:50:39

Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode):

"TimerQueue" daemon prio=6 tid=0x000000000d622800 nid=0x29c4 waiting on condition [0x000000001139f000]

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

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

- parking to wait for <0x00000007d6107530> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionOb

ject)

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

at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2

043)

at java.util.concurrent.DelayQueue.take(DelayQueue.java:209)

at javax.swing.TimerQueue.run(TimerQueue.java:171)

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

"DestroyJavaVM" prio=6 tid=0x000000000d622000 nid=0x2650 waiting on condition [0x0000000000000000]

java.lang.Thread.State: RUNNABLE

"AWT-EventQueue-0" prio=6 tid=0x000000000d621000 nid=0x458 waiting on condition [0x000000000d1df000]

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

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

- parking to wait for <0x0000000781476fd0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionOb

ject)

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

at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2

043)

at java.awt.EventQueue.getNextEvent(EventQueue.java:543)

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

"AWT-Shutdown" prio=6 tid=0x000000000d620800 nid=0x2220 in Object.wait() [0x000000000fe1e000]

java.lang.Thread.State: WAITING (on object monitor)

at java.lang.Object.wait(Native Method)

- waiting on <0x00000007814512a8> (a java.lang.Object)

at java.lang.Object.wait(Object.java:503)

at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:287)

- locked <0x00000007814512a8> (a java.lang.Object)

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

"RMI TCP Connection(idle)" daemon prio=6 tid=0x000000000d6e5800 nid=0x2114 waiting on condition [0x000000000f41e000]

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

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

- parking to wait for <0x00000007817617a8> (a java.util.concurrent.SynchronousQueue$TransferStack)

at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)

at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460)

at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:359)

at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:942)

at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)

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

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

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

"RMI RenewClean-[192.168.1.93:9942]" daemon prio=6 tid=0x000000000d6e3000 nid=0x28dc in Object.wait() [0x000000000fcaf00

0]

java.lang.Thread.State: TIMED_WAITING (on object monitor)

at java.lang.Object.wait(Native Method)

- waiting on <0x00000007d5f11158> (a java.lang.ref.ReferenceQueue$Lock)

at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)

- locked <0x00000007d5f11158> (a java.lang.ref.ReferenceQueue$Lock)

at sun.rmi.transport.DGCClient$EndpointEntry$RenewCleanThread.run(DGCClient.java:535)

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

"RMI Scheduler(0)" daemon prio=6 tid=0x000000000d648800 nid=0x2880 waiting on condition [0x000000000d52f000]

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

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

- parking to wait for <0x00000007817658f0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionOb

ject)

at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)

at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.j

ava:2082)

at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1090)

at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:807)

at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)

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

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

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

"RMI TCP Connection(1)-127.0.0.1" daemon prio=6 tid=0x000000000c82b000 nid=0x23e0 runnable [0x000000000fa8e000]

java.lang.Thread.State: RUNNABLE

at java.net.SocketInputStream.socketRead0(Native Method)

at java.net.SocketInputStream.read(SocketInputStream.java:152)

at java.net.SocketInputStream.read(SocketInputStream.java:122)

at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)

at java.io.BufferedInputStream.read(BufferedInputStream.java:254)

- locked <0x00000007d5ed17d8> (a java.io.BufferedInputStream)

at java.io.FilterInputStream.read(FilterInputStream.java:83)

at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:538)

at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)

at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)

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

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

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

"RMI TCP Accept-1149" daemon prio=6 tid=0x000000000d825800 nid=0x279c runnable [0x000000000d2df000]

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:398)

at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:198)

- locked <0x00000007d5c0af70> (a java.net.SocksSocketImpl)

at java.net.ServerSocket.implAccept(ServerSocket.java:530)

at java.net.ServerSocket.accept(ServerSocket.java:498)

at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:388)

at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:360)

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

"GC Daemon" daemon prio=2 tid=0x000000000d8b8000 nid=0x978 in Object.wait() [0x000000000f95f000]

java.lang.Thread.State: TIMED_WAITING (on object monitor)

at java.lang.Object.wait(Native Method)

- waiting on <0x00000007814515a8> (a sun.misc.GC$LatencyLock)

at sun.misc.GC$Daemon.run(GC.java:117)

- locked <0x00000007814515a8> (a sun.misc.GC$LatencyLock)

"RMI Reaper" prio=6 tid=0x000000000d63a000 nid=0x2578 in Object.wait() [0x000000000f80f000]

java.lang.Thread.State: WAITING (on object monitor)

at java.lang.Object.wait(Native Method)

- waiting on <0x0000000781451678> (a java.lang.ref.ReferenceQueue$Lock)

at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)

- locked <0x0000000781451678> (a java.lang.ref.ReferenceQueue$Lock)

at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)

at sun.rmi.transport.ObjectTable$Reaper.run(ObjectTable.java:351)

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

"RMI TCP Accept-0" daemon prio=6 tid=0x000000000dc2c800 nid=0xc44 runnable [0x000000000f6ef000]

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:398)

at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:198)

- locked <0x00000007814598a8> (a java.net.SocksSocketImpl)

at java.net.ServerSocket.implAccept(ServerSocket.java:530)

at java.net.ServerSocket.accept(ServerSocket.java:498)

at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:388)

at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:360)

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

"AWT-Windows" daemon prio=6 tid=0x000000000c82c000 nid=0x211c runnable [0x000000000d41f000]

java.lang.Thread.State: RUNNABLE

at sun.awt.windows.WToolkit.eventLoop(Native Method)

at sun.awt.windows.WToolkit.run(WToolkit.java:299)

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

"Java2D Disposer" daemon prio=10 tid=0x000000000c828000 nid=0x19a4 in Object.wait() [0x000000000d01f000]

java.lang.Thread.State: WAITING (on object monitor)

at java.lang.Object.wait(Native Method)

- waiting on <0x0000000781547fd8> (a java.lang.ref.ReferenceQueue$Lock)

at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)

- locked <0x0000000781547fd8> (a java.lang.ref.ReferenceQueue$Lock)

at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)

at sun.java2d.Disposer.run(Disposer.java:145)

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

"Service Thread" daemon prio=6 tid=0x000000000ad88800 nid=0x2ab8 runnable [0x0000000000000000]

java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" daemon prio=10 tid=0x000000000ad85800 nid=0x265c waiting on condition [0x0000000000000000]

java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" daemon prio=10 tid=0x000000000ad80800 nid=0x1d58 waiting on condition [0x0000000000000000]

java.lang.Thread.State: RUNNABLE

"Attach Listener" daemon prio=10 tid=0x000000000ad7f000 nid=0x2300 runnable [0x0000000000000000]

java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0x000000000ad78800 nid=0x2118 waiting on condition [0x0000000000000000]

java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=8 tid=0x000000000ad15800 nid=0x26d4 in Object.wait() [0x000000000c0de000]

java.lang.Thread.State: WAITING (on object monitor)

at java.lang.Object.wait(Native Method)

- waiting on <0x0000000781409278> (a java.lang.ref.ReferenceQueue$Lock)

at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)

- locked <0x0000000781409278> (a java.lang.ref.ReferenceQueue$Lock)

at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)

at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:189)

"Reference Handler" daemon prio=10 tid=0x000000000ad0a800 nid=0x1768 in Object.wait() [0x000000000c21f000]

java.lang.Thread.State: WAITING (on object monitor)

at java.lang.Object.wait(Native Method)

- waiting on <0x0000000781408c38> (a java.lang.ref.Reference$Lock)

at java.lang.Object.wait(Object.java:503)

at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)

- locked <0x0000000781408c38> (a java.lang.ref.Reference$Lock)

"VM Thread" prio=10 tid=0x000000000ad06000 nid=0x1438 runnable

"GC task thread#0 (ParallelGC)" prio=6 tid=0x00000000023fc000 nid=0x2164 runnable

"GC task thread#1 (ParallelGC)" prio=6 tid=0x00000000023fd800 nid=0x283c runnable

"GC task thread#2 (ParallelGC)" prio=6 tid=0x00000000023ff000 nid=0x2074 runnable

"GC task thread#3 (ParallelGC)" prio=6 tid=0x0000000002401000 nid=0x2b20 runnable

"VM Periodic Task Thread" prio=10 tid=0x000000000c7a0800 nid=0x2618 waiting on condition

JNI global references: 506

Heap

PSYoungGen total 38400K, used 9276K [0x00000007d5c00000, 0x00000007d8680000, 0x0000000800000000)

eden space 33280K, 27% used [0x00000007d5c00000,0x00000007d650f0f0,0x00000007d7c80000)

from space 5120K, 0% used [0x00000007d7c80000,0x00000007d7c80000,0x00000007d8180000)

to space 5120K, 0% used [0x00000007d8180000,0x00000007d8180000,0x00000007d8680000)

ParOldGen total 86528K, used 3492K [0x0000000781400000, 0x0000000786880000, 0x00000007d5c00000)

object space 86528K, 4% used [0x0000000781400000,0x00000007817690d8,0x0000000786880000)

PSPermGen total 25600K, used 14414K [0x000000077c200000, 0x000000077db00000, 0x0000000781400000)

object space 25600K, 56% used [0x000000077c200000,0x000000077d013840,0x000000077db00000)
View Code

 

这都一大片,考视力么;

技术分享

不过貌似我们可以搜关键字waiting on或者locked看阻塞在哪里和锁了什么;

我们来看个死锁的例子,线程转储是什么样的;

示例:ThreadTest

技术分享

more:

技术分享
F:\360\workspacemy\CovertJava\srcbin>java covertjava.profile.ThreadTest

Thread[Thread-0,5,main] : Inside method1

Thread[Thread-1,5,main] : Inside method2

Thread[Thread-0,5,main] : Method1 got lock1

Thread[Thread-1,5,main] : Method2 got lock2

Thread[Thread-0,5,main] : Waiking up

Thread[Thread-1,5,main] : Waiking up

2015-05-12 10:56:30

Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode):

"DestroyJavaVM" prio=6 tid=0x00000000025fd800 nid=0x2a8c waiting on condition [0x0000000000000000]

java.lang.Thread.State: RUNNABLE

"Thread-1" prio=6 tid=0x000000000c88b800 nid=0xec8 waiting for monitor entry [0x000000000cefe000]

java.lang.Thread.State: BLOCKED (on object monitor)

at covertjava.profile.ThreadTest.method2(ThreadTest.java:34)

- waiting to lock <0x00000007d5c9ad38> (a java.lang.Object)

- locked <0x00000007d5c9ad48> (a java.lang.Object)

at covertjava.profile.ThreadTest$2.run(ThreadTest.java:66)

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

"Thread-0" prio=6 tid=0x000000000c889000 nid=0x2070 waiting for monitor entry [0x000000000d03f000]

java.lang.Thread.State: BLOCKED (on object monitor)

at covertjava.profile.ThreadTest.method1(ThreadTest.java:20)

- waiting to lock <0x00000007d5c9ad48> (a java.lang.Object)

- locked <0x00000007d5c9ad38> (a java.lang.Object)

at covertjava.profile.ThreadTest$1.run(ThreadTest.java:61)

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

"Service Thread" daemon prio=6 tid=0x000000000ac0b000 nid=0x2758 runnable [0x0000000000000000]

java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" daemon prio=10 tid=0x000000000ac09000 nid=0x2a68 waiting on condition [0x0000000000000000]

java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" daemon prio=10 tid=0x000000000ac04000 nid=0x1b3c waiting on condition [0x0000000000000000]

java.lang.Thread.State: RUNNABLE

"Attach Listener" daemon prio=10 tid=0x000000000ac03000 nid=0x2ac8 runnable [0x0000000000000000]

java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0x000000000abfc000 nid=0x28a4 waiting on condition [0x0000000000000000]

java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=8 tid=0x000000000ab97000 nid=0x2538 in Object.wait() [0x000000000c27f000]

java.lang.Thread.State: WAITING (on object monitor)

at java.lang.Object.wait(Native Method)

- waiting on <0x00000007d5c05568> (a java.lang.ref.ReferenceQueue$Lock)

at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)

- locked <0x00000007d5c05568> (a java.lang.ref.ReferenceQueue$Lock)

at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)

at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:189)

"Reference Handler" daemon prio=10 tid=0x000000000ab8e000 nid=0x2760 in Object.wait() [0x000000000c08f000]

java.lang.Thread.State: WAITING (on object monitor)

at java.lang.Object.wait(Native Method)

- waiting on <0x00000007d5c050f0> (a java.lang.ref.Reference$Lock)

at java.lang.Object.wait(Object.java:503)

at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)

- locked <0x00000007d5c050f0> (a java.lang.ref.Reference$Lock)

"VM Thread" prio=10 tid=0x000000000ab86000 nid=0x2600 runnable

"GC task thread#0 (ParallelGC)" prio=6 tid=0x000000000244c000 nid=0x2604 runnable

"GC task thread#1 (ParallelGC)" prio=6 tid=0x000000000244d800 nid=0x12b4 runnable

"GC task thread#2 (ParallelGC)" prio=6 tid=0x000000000244f800 nid=0x268c runnable

"GC task thread#3 (ParallelGC)" prio=6 tid=0x0000000002451000 nid=0x2974 runnable

"VM Periodic Task Thread" prio=10 tid=0x000000000c880800 nid=0x1940 waiting on condition

JNI global references: 105

Found one Java-level deadlock:

=============================

"Thread-1":

waiting to lock monitor 0x000000000ab944f8 (object 0x00000007d5c9ad38, a java.lang.Object),

which is held by "Thread-0"

"Thread-0":

waiting to lock monitor 0x000000000ab96e38 (object 0x00000007d5c9ad48, a java.lang.Object),

which is held by "Thread-1"

Java stack information for the threads listed above:

===================================================

"Thread-1":

at covertjava.profile.ThreadTest.method2(ThreadTest.java:34)

- waiting to lock <0x00000007d5c9ad38> (a java.lang.Object)

- locked <0x00000007d5c9ad48> (a java.lang.Object)

at covertjava.profile.ThreadTest$2.run(ThreadTest.java:66)

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

"Thread-0":

at covertjava.profile.ThreadTest.method1(ThreadTest.java:20)

- waiting to lock <0x00000007d5c9ad48> (a java.lang.Object)

- locked <0x00000007d5c9ad38> (a java.lang.Object)

at covertjava.profile.ThreadTest$1.run(ThreadTest.java:61)

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

Found 1 deadlock.

Heap

PSYoungGen total 38400K, used 2662K [0x00000007d5c00000, 0x00000007d8680000, 0x0000000800000000)

eden space 33280K, 8% used [0x00000007d5c00000,0x00000007d5e99a88,0x00000007d7c80000)

from space 5120K, 0% used [0x00000007d8180000,0x00000007d8180000,0x00000007d8680000)

to space 5120K, 0% used [0x00000007d7c80000,0x00000007d7c80000,0x00000007d8180000)

ParOldGen total 86528K, used 0K [0x0000000781400000, 0x0000000786880000, 0x00000007d5c00000)

object space 86528K, 0% used [0x0000000781400000,0x0000000781400000,0x0000000786880000)

PSPermGen total 21504K, used 2483K [0x000000077c200000, 0x000000077d700000, 0x0000000781400000)

object space 21504K, 11% used [0x000000077c200000,0x000000077c46cf40,0x000000077d700000)
View Code

 

看这个

技术分享

Found one Java-level deadlock:

=============================

"Thread-1":

waiting to lock monitor 0x000000000ab944f8 (object 0x00000007d5c9ad38, a java.lang.Object),

which is held by "Thread-0"

"Thread-0":

waiting to lock monitor 0x000000000ab96e38 (object 0x00000007d5c9ad48, a java.lang.Object),

which is held by "Thread-1"

她找到了死锁!但要是能把变量名也打印出来那就更好了;

技术分享

所以说一切都是不完美的,包括你、我、她;

使用线程转储研究运行时的应用程序

标签:

原文地址:http://www.cnblogs.com/yejq/p/4501576.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!