import java.io.*;
import java.lang.Thread;public class testpc { /**
 * @param args
 */

public static void main(String[] args) {
// TODO Auto-generated method stub
CubbyHole c = new CubbyHole();
producer p = new producer(c);
consumer con = new consumer(c);
p.start();
con.start();
}}
public class CubbyHole{
private int contents;
private boolean avaiable = false;
public synchronized int get(){
while(avaiable==false){
try{
wait();
}catch(InterruptedException e)
{
System.out.println(e.toString());
}
}
avaiable=false;
notifyAll();
return contents;
}
public synchronized void put(int value){
while(avaiable==true){
try{
wait();
}catch(InterruptedException e)
{
System.out.println(e.toString());
}
}
contents = value;
avaiable=true;
notifyAll();
}
}public class consumer extends Thread{
private CubbyHole c;
consumer(CubbyHole c){
this.c = c;
}
public void run(){
for(int i=0;i<10;i++){
System.out.println(c.get() + "get");
}
}
}public class producer extends Thread{
CubbyHole c ;
producer(CubbyHole c){
this.c=c;
}
public void run(){
for(int i=0;i<10;i++){
c.put(i);
System.out.println(i + "put");
try{
sleep(1000);
}catch(InterruptedException e){
System.out.println(e.toString());
}
}
}
}