2 Replies Latest reply: Feb 21, 2007 7:59 AM by 807606 RSS

    wait and notify

    807606
      Folks,

      Why wait and notify methods belong to Object class when we use them only with threads. Shouldnt it be within Thread class ?

      This was one interview questions asked to me.
        • 1. Re: wait and notify
          807606
          Never thought about it before, but I'm guessing that each object has to be run by a thread, so even if you don't implement runnable or extend thread, there is still a thread running the Java application.
          • 2. Re: wait and notify
            807606
            The wait() and notify() methods are object-specific. The wait() method suspends the current thread of execution, and tells the object to keep track of the suspended thread. The notify() method tells the object to wake up the suspended threads that it is currently keeping track of. Since wait() and notify() are object specific, they must be used within code that is synchronized on the object in question.

            from:
            http://www.jguru.com/faq/view.jsp?EID=43568