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

Discussion

Which of these declares a lock acquisition that can be interrupted while waiting?

  • A.lock.lock();
  • B.lock.tryLock();
  • C.synchronized (lock) { }
  • D.lock.lockInterruptibly();

Answer: D

lockInterruptibly declares InterruptedException and abandons the attempt if the thread is interrupted while waiting. Plain lock ignores interruption, tryLock returns immediately, and a synchronized block cannot be interrupted at all.

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

Post your comment

Please log in or register to post a comment.