查找死锁发生的位置

查看本机jvm进程(运行了Test类中的main方法)

D:\soft\Java\jdk1.8.0_131\bin>jps
2516
6756 Launcher
6820 Jps
2472 Test
8424
找到了Test进程id为:2472

jstack命令查看当前线程堆栈调用情况

D:\soft\Java\jdk1.8.0_131\bin>jstack
Usage:
jstack [-l]
(to connect to running process)
jstack -F [-m] [-l]
(to connect to a hung process)
jstack [-m] [-l]
(to connect to a core file)
jstack [-m] [-l] [server_id@]
(to connect to a remote debug server)

Options:
-F to force a thread dump. Use when jstack does not respond (process is hung)
-m to print both java and native frames (mixed mode)
-l long listing. Prints additional information about locks
-h or -help to print this help message

D:\soft\Java\jdk1.8.0_131\bin>jstack 2472
2019-11-11 13:58:51
Full thread dump OpenJDK 64-Bit Server VM (11.0.3+12-b304.56 mixed mode, sharing):

Threads class SMR info:
_java_thread_list=0x00000247257519f0, length=13, elements={
0x0000024724cf8800, 0x0000024724cf9800, 0x0000024724d1b000, 0x0000024724d1c000,
0x0000024724d1d800, 0x0000024724d2a800, 0x0000024724d2f800, 0x0000024724cdd800,
0x000002472575b800, 0x000002472575c800, 0x0000024725772800, 0x0000024725777800,
0x0000024709de6000
}

"Reference Handler" #2 daemon prio=10 os_prio=2 cpu=0.00ms elapsed=114.56s tid=0x0000024724cf8800 nid=0x9bc waiting on condition [0x000000d1bb5fe000]
java.lang.Thread.State: RUNNABLE
at java.lang.ref.Reference.waitForReferencePendingList([email protected]/Native Method)
at java.lang.ref.Reference.processPendingReferences([email protected]/Reference.java:241)
at java.lang.ref.Reference$ReferenceHandler.run([email protected]/Reference.java:213)

"Finalizer" #3 daemon prio=8 os_prio=1 cpu=0.00ms elapsed=114.56s tid=0x0000024724cf9800 nid=0x24b0 in Object.wait() [0x000000d1bb6fe000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait([email protected]/Native Method)
- waiting on <0x0000000089f0a2b0> (a java.lang.ref.ReferenceQueueLock)
at java.lang.ref.ReferenceQueue.remove([email protected]/ReferenceQueue.java:176)
at java.lang.ref.Finalizer$FinalizerThread.run([email protected]/Finalizer.java:170)

"Signal Dispatcher" #4 daemon prio=9 os_prio=2 cpu=0.00ms elapsed=114.55s tid=0x0000024724d1b000 nid=0x21d8 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

"Attach Listener" #5 daemon prio=5 os_prio=2 cpu=15.63ms elapsed=114.55s tid=0x0000024724d1c000 nid=0x2a4 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #6 daemon prio=9 os_prio=2 cpu=46.88ms elapsed=114.55s tid=0x0000024724d1d800 nid=0x5c0 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
No compile task

"C1 CompilerThread0" #9 daemon prio=9 os_prio=2 cpu=78.13ms elapsed=114.55s tid=0x0000024724d2a800 nid=0x448 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
No compile task

"Sweeper thread" #10 daemon prio=9 os_prio=2 cpu=0.00ms elapsed=114.55s tid=0x0000024724d2f800 nid=0xa84 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

"Common-Cleaner" #11 daemon prio=8 os_prio=1 cpu=0.00ms elapsed=114.52s tid=0x0000024724cdd800 nid=0x1c54 in Object.wait() [0x000000d1bbcfe000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait([email protected]/Native Method)
- waiting on <0x0000000089e2bca8> (a java.lang.ref.ReferenceQueueLock)
at jdk.internal.ref.CleanerImpl.run([email protected]/CleanerImpl.java:148)
at java.lang.Thread.run([email protected]/Thread.java:834)
at jdk.internal.misc.InnocuousThread.run([email protected]/InnocuousThread.java:134)

"Monitor Ctrl-Break" #12 daemon prio=5 os_prio=0 cpu=15.63ms elapsed=114.48s tid=0x000002472575b800 nid=0x24e8 runnable [0x000000d1bbefe000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0([email protected]/Native Method)
at java.net.SocketInputStream.socketRead([email protected]/SocketInputStream.java:115)
at java.net.SocketInputStream.read([email protected]/SocketInputStream.java:168)
at java.net.SocketInputStream.read([email protected]/SocketInputStream.java:140)
at sun.nio.cs.StreamDecoder.readBytes([email protected]/StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead([email protected]/StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read([email protected]/StreamDecoder.java:178)
- locked <0x0000000089b061b0> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read([email protected]/InputStreamReader.java:185)
at java.io.BufferedReader.fill([email protected]/BufferedReader.java:161)
at java.io.BufferedReader.readLine([email protected]/BufferedReader.java:326)
- locked <0x0000000089b061b0> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine([email protected]/BufferedReader.java:392)
at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:64)

"Service Thread" #13 daemon prio=9 os_prio=0 cpu=0.00ms elapsed=114.48s tid=0x000002472575c800 nid=0x1370 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

"Thread-1" #14 prio=5 os_prio=0 cpu=15.63ms elapsed=114.48s tid=0x0000024725772800 nid=0x25e0 waiting for monitor entry [0x000000d1bc1ff000]
java.lang.Thread.State: BLOCKED (on object monitor)
at deadlock.Target.method1(Target.java:18)
- waiting to lock <0x0000000089d903a8> (a java.lang.Object)
- locked <0x0000000089d90398> (a java.lang.Object)
at deadlock.Target.run(Target.java:41)
at java.lang.Thread.run([email protected]/Thread.java:834)

"Thread-2" #15 prio=5 os_prio=0 cpu=15.63ms elapsed=114.48s tid=0x0000024725777800 nid=0x408 waiting for monitor entry [0x000000d1bc2fe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at deadlock.Target.method2(Target.java:32)
- waiting to lock <0x0000000089d90398> (a java.lang.Object)
- locked <0x0000000089d903a8> (a java.lang.Object)
at deadlock.Target.run(Target.java:43)
at java.lang.Thread.run([email protected]/Thread.java:834)

"DestroyJavaVM" #16 prio=5 os_prio=0 cpu=109.38ms elapsed=114.48s tid=0x0000024709de6000 nid=0x25cc waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

"VM Thread" os_prio=2 cpu=0.00ms elapsed=114.56s tid=0x0000024724cf7000 nid=0x1e78 runnable

"GC Thread#0" os_prio=2 cpu=0.00ms elapsed=114.58s tid=0x0000024709dfe800 nid=0xd84 runnable

"G1 Main Marker" os_prio=2 cpu=0.00ms elapsed=114.58s tid=0x0000024709e30800 nid=0x2520 runnable

"G1 Conc#0" os_prio=2 cpu=0.00ms elapsed=114.58s tid=0x0000024709e32000 nid=0x1d64 runnable

"G1 Refine#0" os_prio=2 cpu=0.00ms elapsed=114.58s tid=0x0000024724b90800 nid=0x1268 runnable

"G1 Young RemSet Sampling" os_prio=2 cpu=0.00ms elapsed=114.58s tid=0x0000024724b91800 nid=0x794 runnable
"VM Periodic Task Thread" os_prio=2 cpu=0.00ms elapsed=114.48s tid=0x000002472576d800 nid=0x1454 waiting on condition

JNI global refs: 16, weak refs: 0

Found one Java-level deadlock:

"Thread-1":
waiting to lock monitor 0x0000024724d0b500 (object 0x0000000089d903a8, a java.lang.Object),
which is held by "Thread-2"
"Thread-2":
waiting to lock monitor 0x0000024724d09100 (object 0x0000000089d90398, a java.lang.Object),
which is held by "Thread-1"

Java stack information for the threads listed above:

"Thread-1":
at deadlock.Target.method1(Target.java:18)
- waiting to lock <0x0000000089d903a8> (a java.lang.Object)
- locked <0x0000000089d90398> (a java.lang.Object)
at deadlock.Target.run(Target.java:41)
at java.lang.Thread.run([email protected]/Thread.java:834)
"Thread-2":
at deadlock.Target.method2(Target.java:32)
- waiting to lock <0x0000000089d90398> (a java.lang.Object)
- locked <0x0000000089d903a8> (a java.lang.Object)
at deadlock.Target.run(Target.java:43)
at java.lang.Thread.run([email protected]/Thread.java:834)

Found 1 deadlock.

method1和method2存在死锁

你可能感兴趣的:(查找死锁发生的位置)