notifyAll() Will notify all waiting threads
notify() Will notify one of the waiting threads
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
SCJP2. Please Indent your code using UBB Code
SCJP2. Please Indent your code using UBB Code
It would have beeen woken to just becoming a waiting thread again
I remember to have read that is advisable to use notifyAll whenever there is more than one waiting thread because some JVM
could choose the thread to be woken based on the span of time the thread is in the wait set. If such implementation always
chooses the more recently thread added to the set, and the set has always threads in it, the thread waiting for the longest
time would not be chosen to wake up ever.
Ugly thing to depend on implementation details eh?
Does anybody know if this concern is still applicable?
it might be required that we want a particular thread to proceed
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
from my personal point of view i think that waking only one thread will be more efficient than waking 100.
SCJP2. Please Indent your code using UBB Code
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
SCJP2. Please Indent your code using UBB Code
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
The point if that if the threads are doing different tasks you cannot permit to notify only one (random) thread. The change of the waiting condition must mean a notification to a proper thread so that it continues with the task they are supposed to be collaborating on. If the randomly chosen thread was not waiting on that condition the notification is lost.
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
it's upto the programmer to make sure that the correct thread is selected
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
Wakes up all threads that are waiting on this object's monitor. A thread waits on an object's monitor by calling one of the wait methods.
The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.
Alexan Kahkejian<br />SCJP<br />SCWCD<br /><a href="http://www.javaemployer.com" target="_blank" rel="nofollow">http://www.javaemployer.com</a>
SCJP2. Please Indent your code using UBB Code
Originally posted by Vicken Karaoghlanian:
but i think that the priority of the waiting threads increases
Does the priority of a thread ever increase/decrease during its lifetime ?
the priority of the waiting threads increases implicitly from time to time to prevent starvation.
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
catch it before it slithers away! Oh wait, it's a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|