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