代码
public class ThreadTest3 {
public static void main(String[] args) {
Thread t1 = new Thread() {
@Override
public void run() {
synchronized (Object.class) {
for (int i = 1; i < 53; i++) {
System.out.print(i);
if (i % 2 == 0) {
try {
Object.class.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Object.class.notifyAll();
}
}
}
};
Thread t2 = new Thread() {
@Override
public void run() {
synchronized (Object.class) {
for (char j = 65; j <= 90; j++) {
System.out.print(j);
Object.class.notifyAll();
if (j != 90) {
try {
Object.class.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
};
t1.start();
t2.start();
}
}