import java
.util
.concurrent
.CountDownLatch
;
public class JUCDoor {
public static void main(String
[] args
) {
final Object o
= new Object();
char[] a
= new char[26];
for (int i
= 0; i
< 26; i
++) {
a
[i
] = (char) (97 + i
);
}
CountDownLatch countDownLatch
= new CountDownLatch(1);
new Thread(()->{
synchronized (o
) {
for (int i
= 1; i
<= 26; i
++) {
System
.out
.print(i
);
try {
countDownLatch
.countDown();
o
.notify();
o
.wait();
} catch (InterruptedException e
) {
e
.printStackTrace();
}
}
}
},"A").start();
new Thread(()->{
try {
countDownLatch
.await();
} catch (InterruptedException e
) {
e
.printStackTrace();
}
synchronized (o
) {
for (int i
= 0; i
< 26; i
++) {
System
.out
.print(a
[i
]);
try {
o
.notify();
o
.wait();
} catch (InterruptedException e
) {
e
.printStackTrace();
}
}
}
},"B").start();
}
}
await() 阻塞当前线程 ,当count == 0 继续向下执行 toNanos()指向了一个抽象方法错误 一路追溯到一个记录栈状态的类