Acquires a permit, if one is available and returns immediately, with the value {@code true}, reducing the number of available permits by one.
If no permit is available then this method will return immediately with the value {@code false}.
Even when this semaphore has been set to use a fair ordering policy, a call to {@code tryAcquire()} willimmediately acquire a permit if one is available, whether or not other threads are currently waiting. This "barging" behavior can be useful in certain circumstances, even though it breaks fairness. If you want to honor the fairness setting, then use {@link #tryAcquire(long,TimeUnit) tryAcquire(0, TimeUnit.SECONDS) }which is almost equivalent (it also detects interruption). @return {@code true} if a permit was acquired and {@code false}otherwise
If a permit is immediately available, this method returns {@code true} immediately, reducing the number ofavailable permits in the semaphore by one.
If no permit is available then this method will return immediately with the value {@code false}.
Note: Unlike {@link java.util.concurrent.Semaphore#tryAcquire()}, this method will obey ordering policies, and will never acquire a permit at the expense of another party. @return true if a permit has been acquired, false otherwise
|
|
|
|
|
|
|
|
|
|