There's more...

There are other methods in the ReentrantLock class that can be used to obtain information about a Lock object:

  • getHoldCount(): This returns the number of times the current thread has acquired the lock
  • isHeldByCurrentThread(): This returns a Boolean value indicating whether the lock is owned by the current thread

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.