Hi All,
I was trying to implement wait and notify methods for an object but I am unable to call notify method.Please help me if Iam missing something here.
here is the code
public class
thread implements Runnable{
public static void main(
String []args){
thread t1=new thread();
thread t2=new thread();
//Thread mythread1=new Thread(t1,"thread1");
//Thread mythread2=new Thread(t1,"thread2");
t1.wait_mthd();
t1.notify_mthd();
//how can i run notify method???and why above //method call is not releasing lock on t1
}
public synchronized void notify_mthd(){
System.out.println("This is first synchronized notify method ");
this.notify();
System.out.println("This is after notify call");
}
public synchronized void wait_mthd(){
System.out.println("This is synchronized waiting method for "+this);
try{
this.wait();}
catch(InterruptedException e){}
System.out.println("This is waiting method after notified");
}
public void run(){
for(int i=0;i<6;i++){
//this.wait_mthd();
System.out.println("This is first statement after wait"+Thread.currentThread().getName());
}
}
}
thanks in advance
