class Test2 extends Thread{
 public int val;public volatile boolean inited = false;
 public void run(){
  synchronized(this){
   inited =true;
   try{
    while(true){
     wait();System.out.println(val);
    }
   }
   catch(InterruptedException e){}
  }
 }
}
public class Test {
 public static void main(String args[]){
  Thread t = new Test2();
  t.start();
  while(!t.inited)Thread.yield();
  for(int i = 0; i < 3 ; i++){
   syncrhonized(t){t.val=i;t.notify();}
  }
  t.interrupt();
 }
}