Loading

死锁的Dump文件

死锁的Dump文件

package com.stono.thread;

public class DeadLockDemo {
    private static String A = "A";
    private static String B = "B";
    public static void main(String[] args) {
        new DeadLockDemo().deadLock();
    }
    private void deadLock() {
        Thread t1 = new Thread(new Runnable() {
            public void run() {
                synchronized (A) {
                    try {
                        Thread.currentThread().sleep(2000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    synchronized (B) {
                        System.out.println("1");
                    }
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            public void run() {
                synchronized (B) {
                    synchronized (A) {
                        System.out.println("2");
                    }
                }
            }
        });
        t1.start();
        t2.start();
    }
}

dump文件:

2017-12-24 07:49:47
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.5-b02 mixed mode):

"DestroyJavaVM" #12 prio=5 os_prio=0 tid=0x00000000029de800 nid=0x17d8 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Thread-1" #11 prio=5 os_prio=0 tid=0x0000000018c1a000 nid=0x17a4 waiting for monitor entry [0x000000001986f000]
   java.lang.Thread.State: BLOCKED (on object monitor)
	at com.stono.thread.DeadLockDemo$2.run(DeadLockDemo.java:28)
	- waiting to lock <0x00000000d702ba68> (a java.lang.String)
	- locked <0x00000000d702ba98> (a java.lang.String)
	at java.lang.Thread.run(Unknown Source)

"Thread-0" #10 prio=5 os_prio=0 tid=0x0000000018c17000 nid=0xc88 waiting for monitor entry [0x000000001976f000]
   java.lang.Thread.State: BLOCKED (on object monitor)
	at com.stono.thread.DeadLockDemo$1.run(DeadLockDemo.java:19)
	- waiting to lock <0x00000000d702ba98> (a java.lang.String)
	- locked <0x00000000d702ba68> (a java.lang.String)
	at java.lang.Thread.run(Unknown Source)

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

"C1 CompilerThread2" #8 daemon prio=9 os_prio=2 tid=0x0000000017845800 nid=0x1270 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

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

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

"Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x000000001782f000 nid=0x1484 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x0000000018bb3800 nid=0xecc runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" #3 daemon prio=8 os_prio=1 tid=0x0000000002ee0800 nid=0x1618 in Object.wait() [0x0000000018b6f000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	- waiting on <0x00000000d7090180> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(Unknown Source)
	- locked <0x00000000d7090180> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(Unknown Source)
	at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)

"Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x00000000177e8000 nid=0xb9c in Object.wait() [0x0000000018a6e000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	- waiting on <0x00000000d7088210> (a java.lang.ref.Reference$Lock)
	at java.lang.Object.wait(Unknown Source)
	at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
	- locked <0x00000000d7088210> (a java.lang.ref.Reference$Lock)

"VM Thread" os_prio=2 tid=0x00000000177e6800 nid=0x1b70 runnable 

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x0000000002e06000 nid=0xbfc runnable 

"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x0000000002e08000 nid=0x1898 runnable 

"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x0000000002e09800 nid=0x1108 runnable 

"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x0000000002e0b000 nid=0x18ac runnable 

"VM Periodic Task Thread" os_prio=2 tid=0x0000000018c04000 nid=0x684 waiting on condition 

JNI global references: 7


Found one Java-level deadlock:
=============================
"Thread-1":
  waiting to lock monitor 0x0000000002edda68 (object 0x00000000d702ba68, a java.lang.String),
  which is held by "Thread-0"
"Thread-0":
  waiting to lock monitor 0x0000000002ee05b8 (object 0x00000000d702ba98, a java.lang.String),
  which is held by "Thread-1"

Java stack information for the threads listed above:
===================================================
"Thread-1":
	at com.stono.thread.DeadLockDemo$2.run(DeadLockDemo.java:28)
	- waiting to lock <0x00000000d702ba68> (a java.lang.String)
	- locked <0x00000000d702ba98> (a java.lang.String)
	at java.lang.Thread.run(Unknown Source)
"Thread-0":
	at com.stono.thread.DeadLockDemo$1.run(DeadLockDemo.java:19)
	- waiting to lock <0x00000000d702ba98> (a java.lang.String)
	- locked <0x00000000d702ba68> (a java.lang.String)
	at java.lang.Thread.run(Unknown Source)

Found 1 deadlock.

 

posted @ 2017-12-24 07:52  stono  阅读(213)  评论(0编辑  收藏  举报