Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

wait() notify() notifyAll() ???  RSS feed

 
Amitkumar Dhama
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

can anybody tell me,

1.Why wait() notify() and notifyAll() are declared in the Object class instead of Thread class.

Thanking in advance....
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

The reason that these functions are in the Object class is because you want to be able to lock on any object and not only on Thread objects.
For example, let's say i want to lock on a specific Class I created named Lock. Then i can use this code below even though Lock doesn't inherit from Thread (it is just a refular Class in java).



as you can see, we can lock on that object and go to "sleep" (wait) on it anytime we want...

Hope it helped a bit.

Roy
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!