import java.util.*;

public class Queue{

	LinkedList q = new LinkedList();
	
	public synchronized void push(Object o){
		q.add(o);
		System.out.println("I put "+o);
		this.notify();	
	}
	
	public synchronized Object pop(){
		while(q.size() == 0){
			try{this.wait();}
			catch(InterruptedException e){}	
		}	
		return q.remove(0);
	}
	
	public static void main(String[] args){
		Queue q = new Queue();
		Thread p = new Producer(q);
		Thread c = new Consumer(q);	
		c.start();
		p.start();
	}
}

class Producer extends Thread{
	Queue q;
	
	Producer(Queue q){
		this.q = q;	
	}
	
	public void run(){
		int countdown = 10;
		while(countdown>0){
			String s = ""+countdown;
			q.push(s);			
			countdown--;	
			try{
				Thread.sleep(1000);
			}catch(InterruptedException e){}
		}
	}
}


class Consumer extends Thread{
	Queue q;
	
	Consumer(Queue q){
		this.q = q;	
	}
	
	public void run(){
		int countdown = 10;
		while(countdown>0){		
			System.out.print("I'm trying to get...");	 
			String s = (String)q.pop();
			System.out.println("I got "+s);
			countdown--;	
		}	
	}
}