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

There's more...

The Semaphore class has three additional versions of the acquire() method:

  • acquireUninterruptibly(): The acquire() method, when the internal counter of the semaphore is 0, blocks the thread until the semaphore is released. During this period, the thread may be interrupted; if this happens, the method will throw an InterruptedException exception. This version of the acquire operation ignores the interruption of the thread and doesn't throw any exceptions.
  • tryAcquire(): This method tries to acquire the semaphore. If it can, it returns the true value. But if it can't, it returns false instead of being blocked and waits for the release of the semaphore. It's your responsibility to take correct action based on the return value. ...

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