wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes wait(),notify(),notifyAll() in Object class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "wait(),notify(),notifyAll() in Object class" Watch "wait(),notify(),notifyAll() in Object class" New topic
Author

wait(),notify(),notifyAll() in Object class

Syed Rizwan Qadri
Greenhorn

Joined: May 28, 2007
Posts: 6
Hi, everybody,
I am preparing for SCJP. I want to know that we use wait(),notify() and notifyAll() only in thread programming. Then why it is declared in Object class?
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Hi Syed,

This topic was discussed in the forum earlier. Perhaps the following links might be helpful to you.

  • Qn asked by me
  • Qn asked by Suhas



  • HtH.


    Everything has got its own deadline including one's EGO!
    [CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
    dhwani mathur
    Ranch Hand

    Joined: May 08, 2007
    Posts: 621
    ok,i dont have exact explanation but i think that the methods wait(),notify(),notifyall(),can only be called by a thread that is the owner of this object's monitor.

    A thread becomes the owner of the object's monitor in one of three ways:

    By executing a synchronized instance method of that object.
    By executing the body of a synchronized statement that synchronizes on the object.
    For objects of type Class, by executing a synchronized static method of that class.
    Only one thread at a time can own an object's monitor.


    i think thats why these methods are in Object class rather in Thread class.
    Raghavan Muthu
    Ranch Hand

    Joined: Apr 20, 2006
    Posts: 3344

    Dhwani,

    Please have a look at the 2 urls above. You will really get a good explanation given by the experts.
    dhwani mathur
    Ranch Hand

    Joined: May 08, 2007
    Posts: 621
    hey raghavan thanks for explanation!!
    Syed Rizwan Qadri
    Greenhorn

    Joined: May 28, 2007
    Posts: 6
    Thanks, Muthu for your prompt and convincing reply.
    Raghavan Muthu
    Ranch Hand

    Joined: Apr 20, 2006
    Posts: 3344

    Syed,

    So nice of you to thank my father :roll:
    Syed Rizwan Qadri
    Greenhorn

    Joined: May 28, 2007
    Posts: 6
    Sorry,
    So your name is Raghavan.Very sorry
    Raghavan Muthu
    Ranch Hand

    Joined: Apr 20, 2006
    Posts: 3344

    Thats fine.. I was just kidding.

    But "Raghavan" is my name
     
    Don't get me started about those stupid light bulbs.
     
    subject: wait(),notify(),notifyAll() in Object class