Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of these statements about notifyAll() compared with notify() is correct?

  • A.notify() is usually preferred.
  • B.notify() and notifyAll() are interchangeable whenever more than one thread waits.
  • C.notifyAll() should be avoided because it wakes threads waiting on other objects too.
  • D.notifyAll() is usually preferred to notify().

Answer: D

With several threads waiting on one monitor for different conditions, notify may wake one whose condition still does not hold; it returns to waiting and the thread that could have proceeded is never signalled. notifyAll wakes them all to re-test, at some cost in contention. It only ever affects waiters on that same object.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.