• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Why Wait() ,notify(),notifyAll() in Object class

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Folks,

I know it's basic level questaion to ask.

I have doubt is why these there methods wait(),notify(),notifyAll() is in object class?
After so much digging i came up with some solution ->

1. JAVA is root heirarchy language and every ojbect has some internal thread run( like garbage collection thread).So if we put it in Thread then we have to inherit and unnecessariy take overhead of other facility of Thread class.
2.except waiting on thread ,there is condition where we need to wait on database then putting these methods in thread restrict us to inherit thread ,which is not required.
Like this there are couple of more reason. i found.

I just wanted to know the above reason i mentioned is what extent correct . if it is not then what are the reasons?

Thanks in advance.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i am not sure about your idea...but commonly
----------------------------------------------------------
these methods are used to communicate between the threads

-----------------------------------------------------------

thanks & regards,
seetharaman.v
 
Mintoo kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response.

But if it is used for communication b/w thread then why not in thread class? why it is in Object class , does it make sense?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using the search feature of this side, I found this in the FAQ: http://faq.javaranch.com/java/WaitAndNotifyInObjectClass

There were also quite some hits for messages in this forum.
 
Marshal
Posts: 74026
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ilja Preuss:
Using the search feature of this side, I found this in the FAQ: http://faq.javaranch.com/java/WaitAndNotifyInObjectClass

There were also quite some hits for messages in this forum.


Like here, here, and here.
 
Mintoo kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks both of you.
 
Campbell Ritchie
Marshal
Posts: 74026
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome. Hope that sorted out your problem.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic