This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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!...
 
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic