下面的程序为什么不能很好的同步?请高手给看看!public class PCTest4 {
public static void main(String[] args) {
CubbyHole4 c = new CubbyHole4();
Producer p1 = new Producer(c, 1);
Consumer c1 = new Consumer(c, 1);
Producer p2 = new Producer(c, 2);
Consumer c2 = new Consumer(c, 2);

p1.start();
p2.start();
c1.start();
c2.start();
}
}class Producer extends Thread {
private CubbyHole4 cubbyhole4;
private int id; public Producer(CubbyHole4 c, int id) {
cubbyhole4 = c;
this.id = id;
} public void run() {
for(int i=0;i<50;i++){
/*while(true){*/
cubbyhole4.put((int)(100*Math.random()),id);
}
}
}class Consumer extends Thread {
private CubbyHole4 cubbyhole4;
private int id; public Consumer(CubbyHole4 c, int id) {
cubbyhole4 = c;
this.id = id;
} public void run() {
for(int i=0;i<50;i++){
/*while(true){*/
cubbyhole4.get(id);
}
}
}
class CubbyHole4 {
private int goods;
private boolean available;

public CubbyHole4(){
//goods=g;
available=false;
} public synchronized int get(int id) {
while (available == false) { 
try {
System.out.println("Consumer #"+id+" is waiting...");
wait(); 
} catch (InterruptedException e) {
}
}
available=false;
System.out.println("Consumer #" + id + " got: " + goods);
notify();
return goods;
} public synchronized void put(int value, int id) {
while(available==true){
try {
System.out.println("Producer #"+id+" is waiting...");
wait();
} catch (InterruptedException e) {
}
}
available=true;
goods=value;
System.out.println("Producer #" + id + " put: " + goods);
notify();
}
}