|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.concurrent.Semaphore com.groiss.ds.CountedSemaphore
public class CountedSemaphore
A CountedSemaphore (from Dijkstra) where waiting threads are handled in FIFO order. Moreover you can specify the amount of threads waiting for the resource. If the waiting queue is full the next caller will receive an QueueFullException.
Constructor Summary | |
---|---|
CountedSemaphore(int threadsRunning)
Construct a new semaphore. |
|
CountedSemaphore(int threadsRunning,
int threadsWaiting)
Construct a new semaphore. |
Method Summary | |
---|---|
static void |
addSemaphore(java.lang.String id,
CountedSemaphore s)
Add a new semaphore to the semaphore table |
static CountedSemaphore |
getSemaphore(java.lang.String id)
Get the semaphore with key 'id' from the semaphore table |
void |
P()
Enter the critical section. |
void |
V()
Leave the critical section. |
Methods inherited from class java.util.concurrent.Semaphore |
---|
acquire, acquire, acquireUninterruptibly, acquireUninterruptibly, availablePermits, drainPermits, getQueuedThreads, getQueueLength, hasQueuedThreads, isFair, reducePermits, release, release, toString, tryAcquire, tryAcquire, tryAcquire, tryAcquire |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CountedSemaphore(int threadsRunning)
threadsRunning
- how many threads can go into the critical section.public CountedSemaphore(int threadsRunning, int threadsWaiting)
threadsRunning
- how many threads can go into the critical section.threadsWaiting
- how many threads may wait.Method Detail |
---|
public static CountedSemaphore getSemaphore(java.lang.String id)
public static void addSemaphore(java.lang.String id, CountedSemaphore s)
public void P() throws QueueFullException
QueueFullException
- when waiting queue is full.public void V()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |