I am having a lot of difficulty in using notify and notifyAll methods.Whenever i try to do so i get IllegalMonitorStateException:current class not owner. Please help me out.Please explain what this means and where am i doing wrong and what is the correct way to do it.All the books on this issue seem to confuse me.Here is my code.all the places where i have tried notify has been commented.they were just guess works!!
class threads_a extends base2all implements Runnable {
Thread t;
public threads_a(String str) { t=new Thread(this,str); t.start(); //notifyAll();
}
synchronized public void run() { try { for(int i=0;i<8;i++) { System.out.println("The Current Thread is : "+t.currentThread()+"
There lies the problem.actually my concept about these is not very clear.I fail to understand these terms.Technically i know about these but practically i don't.please help with these(wait(),notify(),notifyAll()) methods.i mean what does owning a lock mean and how do i know who is owning it
By "owning the lock on an object", he means being inside a synchronized method of that object, or a block synchronized on that object. So, for example, this code is legal: