public final class AdjustableSemaphore extends Object implements Serializable
| 构造器和说明 |
|---|
AdjustableSemaphore() |
AdjustableSemaphore(int maxPermits) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
acquire()
Acquires a permit from this semaphore, blocking until one is
available, or the thread is interrupted.
|
int |
availablePermits()
Returns the current number of permits available in this semaphore.
|
int |
getMaxPermits() |
boolean |
isAvailable()
Returns if the permits is available of the semaphore.
|
void |
release()
Releases a permit, returning it to the semaphore.
|
void |
setMaxPermits(int newMaxPermits)
Adjusts the maximum number of available permits.
|
boolean |
tryAcquire()
Acquires a permit from this semaphore, only if one is available at the
time of invocation.
|
public AdjustableSemaphore()
public AdjustableSemaphore(int maxPermits)
public int getMaxPermits()
public void setMaxPermits(int newMaxPermits)
newMaxPermits - max number of permitspublic void release()
public void acquire()
throws InterruptedException
InterruptedException - if the current thread is interruptedpublic boolean tryAcquire()
true if a permit was acquired and false
otherwisepublic int availablePermits()
public boolean isAvailable()
true if current number of permits > 0Copyright © 2021. All rights reserved.