void waitForSignal(){
Object ob =new Object();
synchronized (Thred.currentThread()) {
try {
ob.wait();
ob.notify();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
This Methods Throws an IllegalMonitorStateException. Can some one explain why so.
Thanks in advance
You should only invoke
waiton the object that you have acquired lock on.In your code, you have acquried lock on
Thread.currentThread(), but you are invoking it onob, which will throwIllegalMonitorStateException.So, you should rather change your synchronized block to: –