O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required