• Post Reply Bookmark Topic Watch Topic
  • New Topic

Clarification needed regarding wait(), notify() and notifyAll()  RSS feed

 
Keerthi Kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please let me know other than Thread programming, where else the java object's wait(), notify() and notifyAll() methods will be used. Are these methods used only for inter thread communication? or for any other instances as well.

Awaiting for your answers.

Thanks,
Keerthi Kumar N
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, these are thread specific things.
 
Keerthi Kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks a lot for your valualbe feedback. But I have one more question. When these methods are used only for thread specific actions, then why those methods are not in the thread class? Are those methods being used apart from threading programs?
 
Henry Wong
author
Sheriff
Posts: 22857
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keerthi Kumar wrote:
Thanks a lot for your valualbe feedback. But I have one more question. When these methods are used only for thread specific actions, then why those methods are not in the thread class? Are those methods being used apart from threading programs?


Well, there are two ways to answer this...

Notifications is more related to synchronization, meaning more related to the data than to the thread -- so it makes more sense to make it methods of the object class, since you can synchronize with any object.

On the other hand, there are some cases where it is not a one-to-one with the object being synchronized, so having it as part of the object class may not have been the best option.


Anyway, take a look at the ReentrantLock, and the Condition variable that is returned from that class -- for a better design of synchronization and the wait/notify mechanism.

Henry
 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it might help you

http://faq.javaranch.com/java/WaitAndNotifyInObjectClass
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!