Forums Register Login

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

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
thanks for your reply!...
He baked a muffin that stole my car! And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 858 times.
Similar Threads
join() confusion
join()
wait and notify..test
Thread
Dan's exam question
Interrupt method + volatile modifier?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:28:12.