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

Discussion

Consider what Condition.await() requires of its caller. Which statement is correct?

  • A.Condition.await() is a static method that suspends the current thread.
  • B.Condition.await() requires the associated lock to be held, mirroring wait() and its monitor.
  • C.Condition.await() may be called without holding the associated lock.
  • D.Condition.await() acquires the associated lock for the caller before returning.

Answer: B

A Condition belongs to a Lock and plays the same role wait and notify play for a monitor: the lock must be held, await releases it while waiting and reacquires it before returning. The advantage is that one lock can carry several conditions, so waiters for different states can be signalled separately.

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

Post your comment

Please log in or register to post a comment.