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

Discussion

Which monitors wait() releases - which of the following is true?

  • A.wait() unlocks no monitors at all; it only suspends the thread.
  • B.wait() unlocks every monitor except the one belonging to the current thread's class.
  • C.wait() unlocks only the object it is called on; other monitors the thread holds remain locked.
  • D.wait() unlocks every monitor the calling thread currently holds.

Answer: C

The javadoc is precise here: wait places the thread in the wait set for this object and unlocks only this object. Any other object the thread is synchronized on stays locked while it waits, which is one of the standard routes into deadlock when a thread waits while holding a second lock.

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

Post your comment

Please log in or register to post a comment.