日期:2014-05-20 浏览次数:20847 次
package WaitAndNotify;
public class Test {
    public static void main(String []args) throws InterruptedException{
        waiter w=new waiter();
        notifyer n=new notifyer(w);
        w.start();
        n.start();
    }
}
class waiter extends Thread{
    public synchronized  void run(){    
        try {
            sleep(1000);
            System.out.println("Going wait");
            wait();
            System.out.println("wake up");
        } catch (InterruptedException e) {
            System.out.println("Interrupt");
        }
    }
}
class notifyer extends Thread{
    waiter t;
    public notifyer(waiter t){
        this.t=t;
    }
    public void run(){
        System.out.println("Going  notify");
        synchronized (t) {
            t.notify();
        }
        System.out.println("Notify Over");
    }
}