java - Directed notifyAll() -
If I can do a question.
Suppose that my main thread creates 3 threads. These 3 threads wait on a fixed object () Then inform the main thread to notify all the objects.
How can I ensure with Thread 2, and only Thread 2, when notifications from Thread 1 and Thread 3 are ignored and come back in the waiting position?
In short, how can I direct my notification to a selected thread?
If I'm not mistaken, doing so in Java 5 would be very simple. Will create a different situation and the main thread will only satisfy the condition in which thread 2 is waiting.
However, how would I solve it in pre5?
Cheers, Vic
You should keep in mind that threads without any < Code> notify without ease. So you always need some kind of condition. The common form of code is:
synchronize (lock ob) {while (Condition!) {LockObj.wait (); }}
Threads that perform specific actions may be due to performance due to just being awake. Consider this for java.util.concurrent.locks
, but note that this is a display issue, not the right issue.
Comments
Post a Comment