This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question on wait().

 
Ruchika Kapoor
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do we have wait() in Object class rather than in Thread class.

Thanks,
Ruchika
 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine that you are standing in a crowd to meet a VIP one-on-one. Everyone is rushing in to meet him/her. Now who should say - "Hey!wait.. come in a queue" ?? You(i mean, one of the waiting people) or the VIP(or his/her bodyguards) ?? Similar case for object and threads. Many threads try to access the object and only the object says - wait or next(notify). Pretty good question actually
 
Dragan Stankovic
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like your example. I'll use it for sure when asked to explain wait()
 
Campbell Ritchie
Sheriff
Posts: 48402
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dragan Stankovic:
I like your example.


Yes, it is a nice analogy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic