What is the significance of wait() method ?

What is the significance of wait() method with respect to Object class, not in Thread class?

Questions by sathireddy   answers by sathireddy

Showing Answers 1 - 2 of 2 Answers

sivakumar

  • Mar 27th, 2006
 

the wait() method is defined in the java.lang.OBject() class and not in the java.lang.Thread()class. it's signature is public static void wait(). we do have some overloaded versions of the wait() method. when an wait method is called by an thread on a object it release the lock on the object and goes to an WAIT/BLOCKED state inorder to let the other threads to enter the RUNNING state. However it regains the Lock on the object after sometime when it moves from the WAIT/BLOCKED state to RUNNABLE state . that can happen due to the call of notify(),notifyAll() methods by other threads holding of the respective objects Lock.

  Was this answer useful?  Yes

According to the Java Specification, the  four methods related to threading is defined in the Object class rather than the Thread Class, because of the Java Concurrency and Synchronised construct. As we start the JDK, there are different therad runs under backgound and it may not be possible to all that object to extends the thread class. So, by definging these method in the Object class, any one can access without extending the Thread Class and ensure synchronisation.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions