Interface Semaphore
- All Known Implementing Classes:
Semaphore.Standard
public interface Semaphore
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidacquire(int acquire) Take permits, waiting indefinitely until availablevoidacquireThrowUncheckedOnInterrupt(int acquire) Take permits, waiting indefinitely until availableintdrain()set the number of permits in this semaphore to zerostatic SemaphorenewFairSemaphore(int permits) Factory method used to capture and redirect instantiations for simulation Construct a fair Semaphore initially holding the specified number of permitsstatic SemaphorenewSemaphore(int permits) Factory method used to capture and redirect instantiations for simulation Construct an unfair Semaphore initially holding the specified number of permitsintpermits()voidrelease(int permits) Increase the number of available permits and signal any waiters that may be served by the releasebooleantryAcquire(int acquire) Try to take permits, returning immediatelybooleantryAcquire(int acquire, long time, TimeUnit unit) Try to take permits, waiting up to timeoutbooleantryAcquireUntil(int acquire, long nanoTimeDeadline) Try to take permits, waiting until the deadline
-
Method Details
-
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
Try to take permits, waiting up to timeout- Returns:
- true iff permits acquired
- Throws:
InterruptedException- if interrupted
-
tryAcquireUntil
Try to take permits, waiting until the deadline- Returns:
- true iff permits acquired
- Throws:
InterruptedException- if interrupted
-
acquire
Take permits, waiting indefinitely until available- Throws:
InterruptedException- if interrupted
-
acquireThrowUncheckedOnInterrupt
Take permits, waiting indefinitely until available- Throws:
UncheckedInterruptedException- if interrupted
-
newSemaphore
Factory method used to capture and redirect instantiations for simulation Construct an unfair Semaphore initially holding the specified number of permits -
newFairSemaphore
Factory method used to capture and redirect instantiations for simulation Construct a fair Semaphore initially holding the specified number of permits
-