标签:=== int rgs thread adt art 代码 private class
代码如下:
/** * 死锁 * */ public class DeadThread { private static Object obj1 = new Object(); private static Object obj2 = new Object(); public static void main(String[] args) { Thread t1 = new Thread(){ public void run(){ synchronized(obj1){ System.out.println(this.getName() + "=====obj1"); synchronized(obj2){ System.out.println(this.getName() + "=====obj2"); } } } }; Thread t2 = new Thread(){ public void run(){ synchronized(obj2){ System.out.println(this.getName() + "=====obj2"); synchronized(obj1){ System.out.println(this.getName() + "=====obj1"); } } } }; t1.start(); t2.start(); } }
此时就会发生死锁
标签:=== int rgs thread adt art 代码 private class
原文地址:https://www.cnblogs.com/bi-hu/p/14725621.html