In a sense, you don't wanna do such a stupid thing like that.
However, before you write code, before you design the program, even before you try to understand the problem, there's one concept you would have to know. What is a Monitor?
A thread technically does NOT call wait, notify or notifyAll. It's the monitor calls wait and puts the current thread to wait. And it's the monitor calls notifyAll and resumes all Threads which have been put to wait on this monitor. notify is just randomly pick one thread to notify. JVM decides which one to notify; no one else has any control of it.
Playing with two interactive threads will easily cause deadlock if not careful. And, that's why stop, suspend, resume, and other methods are deprecated.

解决方案 »

  1.   

    I understand what your meaning,but it is an exersize of thinking in java 2nd in fact. I want to do it but i don't know how to resolve it .can you give me the answer !!
    Thank you very much!!
      

  2.   

    ??up
    who can do it ???
    class t1 extends Thread{
    private t2 thread2;
    public t1(t2 thread2){
       this.thread2=thread2;
       start();
     }
    public synchronized void run(){  
       try{
         System.out.println("t1 run");
         sleep(1000);     
       }catch(InterruptedException e){ System.err.println("Interrupted"); }
       synchronized(thread2){ 
       thread2.notify();
       }
      System.out.println("t1 end");
     }
    }
    class t2 extends Thread{
    public t2(){
    new t1(this);
    start();
    }
    public synchronized void run(){
       try{     
          System.out.println("t2 run"); 
          wait();
          System.out.println("t2 notify");
       }catch(InterruptedException e){
          System.err.println("Interrupted!");
       }
       System.out.println("t2 end");
    }
    }
    public class e3 {
    public static void main(String args[]){
    new t2();
    }
    }
    ***
    this is my program,but i feel it don't accord with the subject.
    waiting....................
      

  3.   

    talking in English!!!I 服了 U!!!“俩笨蛋”----DO YOU KNOW WHAT DOES THIS MEAN?