public class Test {
public static void main(String[] args) {
Object o = new Object();
new Thread(() -> {
synchronized(o){
for (int i=0;i<5;i++) {
System.out.println(i);
try {
o.wait();
} catch (Exception e) {
e.printStackTrace();
}
o.notify();
}
}
}).start();
new Thread(() -> {
synchronized(o){
for (int i=0;i<5;i++) {
System.out.println((char)(65+i));
o.notify();
try {
o.wait();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
}
}
0
A
1
B
2
C
3
D
4
E