我在运行以下程序时遇到了IllegalMonitorStateException,查了一下API文档,好像说当前线程不是monitor的所有者,可是还是没搞明白也就没办法把代码改正,请各位大大帮忙看看:
public class Rendezvous{
int counter;
public synchronized void hurryUpAndWait(){
counter++;
try{
wait();
}
catch(InterruptedException ie){}
}
}
///////////////////////////////////
public class Waiter extends Thread{
public Waiter(){}

public Waiter(Rendezvous r,int id){
rendezvous = r;
this.id = id;
} public void run(){
rendezvous.hurryUpAndWait();
System.out.println("Thread "+id+":Notification has happened!");
}

Rendezvous rendezvous;
int id;
}
////////////////////////////////////////////////
public class Example5{
public static void main(String[] args){
Rendezvous rende = new Rendezvous(); int num = Integer.parseInt(args[0]);
for(int i = 0;i < num;i++){
(new Waiter(rende,i)).start();
} rende.notify(); //就这句抛出了异常
}
}