/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */package TestFiveQuestionTwo;import java.util.logging.Level;
import java.util.logging.Logger;/**
 *
 * @author Administrator
 */
public class Main {    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        A target=new A();
        Thread thread2=new Thread(target);
        thread2.start();
        
        while(target.getStop()==false){}
        
        target.restart();
    }}
class A implements Runnable{
    boolean stop=false;
    A a = null;
    boolean getStop(){
        return stop;
    }
    public void run(){
        for(int i=0;i<=8;i++){
            System.out.println("线程2运行Ing");
            if(i==2){
                try{System.out.println("线程2wait");
                stop=true;
                this.hangUP();
                }catch(Exception e){}
            }
        }
    }
    public synchronized void hangUP()throws InterruptedException{
        this.wait();    }
    
    public synchronized void restart(){
        try {
            Thread.sleep(4000);
            System.out.println("开始执行");
        } catch (InterruptedException ex) {
            Logger.getLogger(A.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.notifyAll();
    }
}
main方法中使用 A.restart()方法时总是没有用

解决方案 »

  1.   

    发现只需要在this.hangUP();上面加一段System.out.println(this);这段代码就可以了,但是不知道为什么,请高手指教!!!
      

  2.   

    main方法中使用 A.restart()方法时总是没有用,没看懂你的意思
    倒是你的程序已经达到你要的效果了的
      

  3.   

    可是我的计算机远行这段代码的时候总是唤醒不了线程thread2
      

  4.   

    我也试了32bit的,正常。LZ可以分享一下64bit的运行结果么,