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 have used the following methods to get information about a semaphore:

  • availablePermits(): This method returns an int value, which is the number of available resources of a semaphore.
  • hasQueuedThreads(): This method returns a Boolean value indicating if there are threads waiting for a resource protected by a semaphore.
  • getQueueLength(): This method returns the number of threads that are waiting for a resource protected by a semaphore.
  • isFair(): This method returns a Boolean value indicating if a semaphore has the fair mode activated. When the fair mode is active (this method returns the true value), and the lock has to select another thread to give to it the access to the shared resource, it selects the ...

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