• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply!...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic