com.groiss.ds
Class CountedSemaphore

java.lang.Object
  extended by java.util.concurrent.Semaphore
      extended by com.groiss.ds.CountedSemaphore
All Implemented Interfaces:
java.io.Serializable

public class CountedSemaphore
extends java.util.concurrent.Semaphore

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.

See Also:
Serialized Form

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

CountedSemaphore

public CountedSemaphore(int threadsRunning)
Construct a new semaphore.

Parameters:
threadsRunning - how many threads can go into the critical section.

CountedSemaphore

public CountedSemaphore(int threadsRunning,
                        int threadsWaiting)
Construct a new semaphore.

Parameters:
threadsRunning - how many threads can go into the critical section.
threadsWaiting - how many threads may wait.
Method Detail

getSemaphore

public static CountedSemaphore getSemaphore(java.lang.String id)
Get the semaphore with key 'id' from the semaphore table


addSemaphore

public static void addSemaphore(java.lang.String id,
                                CountedSemaphore s)
Add a new semaphore to the semaphore table


P

public void P()
       throws QueueFullException
Enter the critical section.

Throws:
QueueFullException - when waiting queue is full.

V

public void V()
Leave the critical section.



@enterprise 8.0.22989 Copyright © 2001-2017 Groiss Informatics GmbH. All Rights Reserved.