• Post Reply Bookmark Topic Watch Topic
  • New Topic

why wait(), notify(), notifyal() methods ,,in Object class  RSS feed

 
ramesh gosala
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...

I have doubt regading wait(), and notify(), and notifyall() methods
this methods is useful only threads.
why this methods give in the object class,insted of giveing Thread class.
only sleep() method is given in Thread class.

What is the reason...for all this methods,
I would be very thankfull to given this answer

Thank you

Ramesh
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a general principle, methods belong in the same class as the data they manipulate. Since these methods manipulate the monitor or "lock" associated with any Object, they belong in Object.

If they were in Thread, then they'd each have to take an Object as an argument, which would make code using them a little messier.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!