Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Wait()... do I understand it right?  RSS feed

 
Andree Charfen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok... So.. I am studying Threading.. so... it is not the simpliest java subject. I want to make sure I understand the wait() method in the java.lang.Object class.
For me.. wait() is very similar to join(). The difference is that when you join another Thread that Thread that joined will stop being at the runnable state until the Thread it joines finishes. Now wait() is pretty much the same deal. Just that with wait() the Thread that is being waited can let the waiting Thread go on at any point of time with a call to notify() or notifyAll().
Ok.. so there it is... correct me or add stuff. Thanks for your help
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
join() is actually implemented using wait(), so your recognition of some similarity is not unfounded. Recognizing this, let me rephrase what you wrote:
join() calls wait() on a Thread object. When the thread completes, the caller of join() is notified because the terminating Thread calls notify() on itself, and then the join() caller can continue.
But wait() and notify() are much more general: you can call then on any object, not just a Thread object. When you call wait(), you freeze until some other Thread calls notify() on that same object.
 
Andree Charfen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply!...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!