Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Ajnam Bujanany
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why notify(),notifyAll() and wait() methods are in Object class and not in Thread Class?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A quick answer might be that wait() and notify() are used to control behaviour of a particular object, which interacts with more than one thread.

A Thread does, of course, have these methods, as it inherits from Object. However, it is rarely, if ever, useful to use wait() and notify() on a Thread.

Look at some typical examples of how wait() and notify() are used, and then think how you'd implement them if wait() and notify() were methods on Thread not Object. Chances are, it would be harder or impossible to achieve the same functionality.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic