Commit f16d3aa3f86456ac43222c47db67070dc7bc9891
1 parent
2fee7384f2
Exists in
master
添加注释信息
Showing 3 changed files with 45 additions and 0 deletions
center.manager/src/test/java/center/manager/test/user/DeadLockTest.java
View file @
f16d3aa
| 1 | +package center.manager.test.user; | |
| 2 | +public class DeadLockTest implements Runnable { | |
| 3 | + private int flag; | |
| 4 | + static Object o1 = new Object(), o2 = new Object(); // 静态的对象,被DeadLockTest的所有实例对象所公用 | |
| 5 | + | |
| 6 | + public void run() { | |
| 7 | + | |
| 8 | + System.out.println(flag); | |
| 9 | + if (flag == 0) { | |
| 10 | + synchronized (o1) { | |
| 11 | + try { | |
| 12 | + Thread.sleep(500); | |
| 13 | + } catch (Exception e) { | |
| 14 | + e.printStackTrace(); | |
| 15 | + } | |
| 16 | + synchronized (o2) { | |
| 17 | + } | |
| 18 | + } | |
| 19 | + } | |
| 20 | + if (flag == 1) { | |
| 21 | + synchronized (o2) { | |
| 22 | + try { | |
| 23 | + Thread.sleep(500); | |
| 24 | + } catch (Exception e) { | |
| 25 | + e.printStackTrace(); | |
| 26 | + } | |
| 27 | + synchronized (o1) { | |
| 28 | + } | |
| 29 | + } | |
| 30 | + } | |
| 31 | + } | |
| 32 | + | |
| 33 | + public static void main(String[] args) { | |
| 34 | + DeadLockTest test1 = new DeadLockTest(); | |
| 35 | + DeadLockTest test2 = new DeadLockTest(); | |
| 36 | + test1.flag = 1; | |
| 37 | + test2.flag = 0; | |
| 38 | + Thread thread1 = new Thread(test1); | |
| 39 | + Thread thread2 = new Thread(test2); | |
| 40 | + thread1.start(); | |
| 41 | + thread2.start(); | |
| 42 | + } | |
| 43 | +} |
core.sdk/src/main/java/com/lyms/sycn/channel/ChannelData.java
View file @
f16d3aa