Hi
To understand the concept of wait() method in Object Class, i have written the following code.
Concept:wait causes the the
thread to release the lock it is holding on an object.
[code]
class TestWait extends Thread{
public synchronized void run(){
for(int i=0;i<10;i++){
System.out.println("New Thread");
System.out.println("I"+" "+i);
}
notify();
System.out.println("After notify");
}
public void Start(){
synchronized(this){
try {
System.out.println("Before Wait");
this.wait();
System.out.println("After Wait");
}catch(InterruptedException e){
e.printStackTrace();
}
}
System.out.println("End");
}
public static void main(
String[] args) {
TestWait testwait=new TestWait();
new TestWait().start();
testwait.Start();
}
}
[code]
There are two threads one -main,two-new thread.when the main thread relases the lock,the new thread continues and finishes its job.the problem is that after calling notify the main thread is not resuming and not finshing the remaining statements[("After Wait"),"End"].why?
Thanks & Regards
Kirba