java: 线程wait()方法

package com.chnfuture;
class MyThread extends Thread{
    MultiThread t = new MultiThread();
    public void run(){
      t.test();
      System.out.println("Thread say:Hello,World!");
    }
}


public class MultiThread {
  
    int x = 0;
    public synchronized void test(){
      if(x==0)
        try{
          wait();
        }catch(Exception e){}
    }
    public static void main(String[] args) throws Exception{
      new MyThread().start();
    }
}
  

 

posted @ 2012-08-10 17:37  ligang305  阅读(114)  评论(0编辑  收藏  举报