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

Discussion

Which one of the following statements about what tryLock() does when the lock is unavailable is true?

  • A.tryLock() returns false rather than blocking when the lock is unavailable.
  • B.tryLock() blocks until the lock becomes available, then returns true.
  • C.tryLock() throws IllegalMonitorStateException when the lock is unavailable.
  • D.tryLock() acquires the lock even if another thread holds it.

Answer: A

tryLock reports whether it succeeded and never waits, which lets a thread back off, do other work or release the locks it already holds rather than sit in a possible deadlock. A monitor has no equivalent: entering a synchronized block either succeeds or blocks.

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

Post your comment

Please log in or register to post a comment.