Interface Semaphore
-
- All Known Implementing Classes:
Semaphore.Standard
public interface Semaphore
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Semaphore.Standard
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description void
acquire(int acquire)
Take permits, waiting indefinitely until availablevoid
acquireThrowUncheckedOnInterrupt(int acquire)
Take permits, waiting indefinitely until availableint
drain()
set the number of permits in this semaphore to zerostatic Semaphore
newFairSemaphore(int permits)
Factory method used to capture and redirect instantiations for simulation Construct a fair Semaphore initially holding the specified number of permitsstatic Semaphore
newSemaphore(int permits)
Factory method used to capture and redirect instantiations for simulation Construct an unfair Semaphore initially holding the specified number of permitsint
permits()
void
release(int permits)
Increase the number of available permits and signal any waiters that may be served by the releaseboolean
tryAcquire(int acquire)
Try to take permits, returning immediatelyboolean
tryAcquire(int acquire, long time, java.util.concurrent.TimeUnit unit)
Try to take permits, waiting up to timeoutboolean
tryAcquireUntil(int acquire, long nanoTimeDeadline)
Try to take permits, waiting until the deadline
-
-
-
Method Detail
-
permits
int permits()
- Returns:
- the number of permits presently in this semaphore
-
drain
int drain()
set the number of permits in this semaphore to zero
-
release
void release(int permits)
Increase the number of available permits and signal any waiters that may be served by the release
-
tryAcquire
boolean tryAcquire(int acquire)
Try to take permits, returning immediately- Returns:
- true iff permits acquired
-
tryAcquire
boolean tryAcquire(int acquire, long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Try to take permits, waiting up to timeout- Returns:
- true iff permits acquired
- Throws:
java.lang.InterruptedException
- if interrupted
-
tryAcquireUntil
boolean tryAcquireUntil(int acquire, long nanoTimeDeadline) throws java.lang.InterruptedException
Try to take permits, waiting until the deadline- Returns:
- true iff permits acquired
- Throws:
java.lang.InterruptedException
- if interrupted
-
acquire
void acquire(int acquire) throws java.lang.InterruptedException
Take permits, waiting indefinitely until available- Throws:
java.lang.InterruptedException
- if interrupted
-
acquireThrowUncheckedOnInterrupt
void acquireThrowUncheckedOnInterrupt(int acquire) throws UncheckedInterruptedException
Take permits, waiting indefinitely until available- Throws:
UncheckedInterruptedException
- if interrupted
-
newSemaphore
static Semaphore newSemaphore(int permits)
Factory method used to capture and redirect instantiations for simulation Construct an unfair Semaphore initially holding the specified number of permits
-
newFairSemaphore
static Semaphore newFairSemaphore(int permits)
Factory method used to capture and redirect instantiations for simulation Construct a fair Semaphore initially holding the specified number of permits
-
-