- permits
- the number of permits to acquire
Documentation for this section has not yet been entered.
Type Reason Java.Lang.IllegalArgumentException if permits is negative
Acquires the given number of permits from this semaphore, only if all are available at the time of invocation.
Acquires the given number of permits, if they are available, and returns immediately, with the value true, reducing the number of available permits by the given amount.
If insufficient permits are available then this method will return immediately with the value false and the number of available permits is unchanged.
Even when this semaphore has been set to use a fair ordering policy, a call to tryAcquirewill immediately 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 Semaphore.TryAcquire(int, System.Int64, System.Int64) which is almost equivalent (it also detects interruption).