Resolved Question
wait(), notify() and notyfyAll() methods
 
Details: Why wait(), notify() and notyfyAll() methods are avialble in Object class but not in Thread class? Explain.
  asked by: sh4d0wz  on: Sep 19, 2009  
 Best Answer ! ! !
bait 's Answer  ( this answer is maked as best answer of this question at: Sep 29, 2009 )


As wait(), notify() and notyfyAll() methods are present in Object class which is a super class for all the classes. There is no need to redefine the same methods in other classes as they all will inherit them from there super class Object.

6 comments  answered on: Sep 27, 2009 
Other Answer (4)
All three methods are used with Threading mechanism.

Thanks
  yukinowa   answered on£ºSep 20, 2009  0 comments

wait() notify() and notyfyAll() methods these are inherited from Object class.
if you call wait() method it will enter in to the monitor for specfic time or ideal time when call notify() it will enter from the waiting pool to ready state
When notifyAll() calls then it will bring all of the waiting threads from waiting pool to ready state

  lkiatl   answered on£ºSep 22, 2009  1 comments

Each object in java is associated with a lock and the wait and notify methods are not associated with a thread but with a lock so coupling locks and objects meant that each object should have wait and notify methods that operate on that object s lock.

Java provides a way to lock the code for a thread which is currently executing it using the synchorinized keyword and making other threads that wish to use it wait until the first thread is finished.These other threads are placed in the waiting state .Once the first thread completes it task than it notifies others in the queue by giving the lock to JVM.Now JVM decides which thread will exceute next by its internal algo.Hence the wait and notify methods has to be in Object class as it acquires lock and has to notify others.....


Contact Us - IT-Interview