How it works...

In this recipe, you implemented the MyLock class that extends the ReentrantLock class to return information that wouldn't have been available otherwise-it's protected data of the ReentrantLock class. The methods implemented by the MyLock class are as follows:

  • getOwnerName(): Only one thread can execute a critical section protected by a Lock object. The lock stores the thread that is executing the critical section. This thread is returned by the protected getOwner() method of the ReentrantLock class.
  • getThreads(): When a thread is executing a critical section, other threads that try to enter it are put to sleep before they continue executing that critical section. The protected method getQueuedThreads() of the ReentrantLock ...

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.