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

Discussion

Which of these is the correct declaration for a read-write lock?

  • A.ReadWriteLock rw = ReentrantLock.readWrite();
  • B.ReadWriteLock rw = new ReentrantReadWriteLock();
  • C.ReadWriteLock rw = new ReadWriteLock();
  • D.ReentrantLock rw = new ReentrantReadWriteLock();

Answer: B

ReadWriteLock is the interface and ReentrantReadWriteLock the only implementation in the API. It is not a ReentrantLock, so the two are not assignable to each other, and its read and write locks are obtained afterwards with readLock and writeLock.

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

Post your comment

Please log in or register to post a comment.