Acquires a permit from this semaphore, blocking until one is available, or the thread is {@link Thread#interrupt interrupted}.
Acquires a permit, if one is available and returns immediately, reducing the number of available permits by one.
If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:
- Some other thread invokes the {@link #release} method for thissemaphore and the current thread is next to be assigned a permit; or
- Some other thread {@link Thread#interrupt interrupts} the currentthread.
If the current thread:
- has its interrupted status set on entry to this method; or
- is {@link Thread#interrupt interrupted} while waitingfor a permit,
then {@link InterruptedException} is thrown and the current thread'sinterrupted status is cleared.
@throws InterruptedException if the current thread is interrupted
@see Thread#interrupt