• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mintoo kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • 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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks both of you.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome. Hope that sorted out your problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic