Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Syed Rizwan Qadri
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    dhwani mathur
    Ranch Hand
    Posts: 621
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 3381
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 621
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hey raghavan thanks for explanation!!
     
    Syed Rizwan Qadri
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks, Muthu for your prompt and convincing reply.
     
    Raghavan Muthu
    Ranch Hand
    Posts: 3381
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Syed,

    So nice of you to thank my father :roll:
     
    Syed Rizwan Qadri
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sorry,
    So your name is Raghavan.Very sorry
     
    Raghavan Muthu
    Ranch Hand
    Posts: 3381
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thats fine.. I was just kidding.

    But "Raghavan" is my name
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic