public static void main(String[] args) {
Object obj = new Object();
Thread3 t3 = new Thread3(obj);
t3.start();
Thread4 thread4 = new Thread4(obj);
Thread t4 = new Thread(thread4);
t4.start();
}
}
class Thread3 extends Thread {
private Object obj;
public Thread3(Object obj) {
this.obj = obj;
}
@Override
public void run() {
synchronized (obj) {
for (int i = 1; i <= 13; i++) {
System.out.print(2 * i - 1+" ");
System.out.print(2 * i+" ");
obj.notifyAll();
try {
if(i < 5)
obj.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
class Thread4 implements Runnable {
private Object obj;
public Thread4(Object obj) {
this.obj = obj;
}
public void run() {
synchronized (obj) {
for (char c = 'A'; c <= 'Z'; c++) {
System.out.print(c+" ");
obj.notifyAll();
try {
if( c < 'E')
obj.wait();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}