public class SemaphoreWithOwners
extends java.util.concurrent.Semaphore
Semaphore
which tracks who created and released the semaphores,
and which requires the same thread to release as created it.| Constructor and Description |
|---|
SemaphoreWithOwners(java.lang.String name) |
SemaphoreWithOwners(java.lang.String name,
int permits,
boolean fair) |
| Modifier and Type | Method and Description |
|---|---|
void |
acquire() |
void |
acquire(int permits) |
void |
acquireUnchecked() |
void |
acquireUnchecked(int numPermits) |
void |
acquireUninterruptibly() |
void |
acquireUninterruptibly(int permits) |
java.lang.String |
getDescription()
caller supplied description
|
java.lang.String |
getName()
constructor-time supplied name
|
java.util.List<java.lang.Thread> |
getOwningThreads()
unmodifiable view of threads owning the permits; threads with multiple permits listed multiply
|
java.util.List<java.lang.Thread> |
getRequestingThreads()
unmodifiable view of threads requesting access (blocked or briefly trying to acquire);
this is guaranteed to be cleared _after_ getOwners
(synchronizing on this class while reading both fields will give canonical access)
|
void |
indicateCallingThreadWillRequest()
Indicate that the calling thread is going to acquire or tryAcquire,
in order to set up the semaphore's isInUse() value appropriately for certain checks.
|
boolean |
isCallingThreadAnOwner()
true iff the calling thread is one of the owners
|
boolean |
isInUse()
true iff there are any owners or any requesters (callers blocked trying to acquire)
|
void |
release() |
void |
release(int permits) |
void |
setDescription(java.lang.String description) |
java.lang.String |
toString() |
boolean |
tryAcquire() |
boolean |
tryAcquire(int permits) |
boolean |
tryAcquire(int permits,
long timeout,
java.util.concurrent.TimeUnit unit) |
boolean |
tryAcquire(long timeout,
java.util.concurrent.TimeUnit unit) |
public SemaphoreWithOwners(java.lang.String name)
public SemaphoreWithOwners(java.lang.String name,
int permits,
boolean fair)
public void acquire()
throws java.lang.InterruptedException
acquire in class java.util.concurrent.Semaphorejava.lang.InterruptedExceptionpublic void acquire(int permits)
throws java.lang.InterruptedException
acquire in class java.util.concurrent.Semaphorejava.lang.InterruptedExceptionpublic void acquireUninterruptibly()
acquireUninterruptibly in class java.util.concurrent.Semaphorepublic void acquireUninterruptibly(int permits)
acquireUninterruptibly in class java.util.concurrent.Semaphorepublic void acquireUnchecked()
public void acquireUnchecked(int numPermits)
public boolean tryAcquire()
tryAcquire in class java.util.concurrent.Semaphorepublic boolean tryAcquire(int permits)
tryAcquire in class java.util.concurrent.Semaphorepublic boolean tryAcquire(int permits,
long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
tryAcquire in class java.util.concurrent.Semaphorejava.lang.InterruptedExceptionpublic boolean tryAcquire(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
tryAcquire in class java.util.concurrent.Semaphorejava.lang.InterruptedExceptionpublic void release()
release in class java.util.concurrent.Semaphorepublic void release(int permits)
release in class java.util.concurrent.Semaphorepublic boolean isInUse()
public boolean isCallingThreadAnOwner()
public java.lang.String getName()
public void setDescription(java.lang.String description)
public java.lang.String getDescription()
public java.util.List<java.lang.Thread> getOwningThreads()
public java.util.List<java.lang.Thread> getRequestingThreads()
public java.lang.String toString()
toString in class java.util.concurrent.Semaphorepublic void indicateCallingThreadWillRequest()