Hi,
In the foll' code, iam sending 5 threads into waiting pool and like to observe the order of their notification. But Im getting Illegal Monitor State Exception. what's wrong?
class NotifyLab
{
static class Rendezvous
{
synchronized public void hurryUpAndWait()
{
System.out.println("*****-------****");
try
{
wait();
}
catch(Exception e)
{
System.out.println(e);
}
}
synchronized public void not()
{
Thread.currentThread().notify();
}
}
static class Waiter extends
Thread {
Rendezvous r;
public Waiter(Rendezvous r,
String name)
{
super(name);
this.r =r;
}
public void run()
{
r.hurryUpAndWait();
System.out.println(Thread.currentThread().getName()+" Notified");
}
}
public static void main(String[] args)
{
Rendezvous r = new Rendezvous();
Waiter wt[] = new Waiter[5];
for(int i=0;i<=4;i++)
{
wt[i] = new Waiter(r,"Thread "+(i+1));
wt[i].start();
}
r.not();
}
}