I am getting an illegal monitor exception. I googled it but nothing clarifies what i am doing wrong.
From this normalclass I create an object for other class and give the object to thread and synchronize the thread. Why am I getting this exception?
/* synchronize the thread object a */
/* here iam calling wait on thread as it need to complete run */
public class Normalclass
{
public static void main(String[] args)
{
NormalThread k = new NormalThread();
Thread a =new Thread(k);
a.setName("test");
a.start();
synchronized(a){
try{
a.wait();
} catch(InterruptedException e){
System.out.println("exception");
}
}
}
}
public class NormalThread implements Runnable
{
public void run()
{
for(int i=0;i<=100;i++)
{
System.out.println(i);
}
notify();
}
}
/* here iam notifying after the run for loop completed*/
// Iam getting illegal monitor exception