org.metasyntactic.thread.concurrent
Class QueuedSemaphore

java.lang.Object
  |
  +--org.metasyntactic.thread.concurrent.Semaphore
        |
        +--org.metasyntactic.thread.concurrent.QueuedSemaphore
All Implemented Interfaces:
Monitor
Direct Known Subclasses:
FirstInFirstOutSemaphore, PrioritySemaphore

public abstract class QueuedSemaphore
extends Semaphore

Abstract base class for semaphores relying on queued wait nodes


Nested Class Summary
protected static class QueuedSemaphore.WaitQueue
          Base class for internal queue classes for semaphores, etc.
 
Field Summary
 
Fields inherited from class org.metasyntactic.thread.concurrent.Semaphore
permits
 
Fields inherited from interface org.metasyntactic.thread.concurrent.Monitor
ONE_CENTURY, ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_SECOND, ONE_WEEK, ONE_YEAR
 
Method Summary
 void acquire()
          Wait until a permit is available, and take one
 boolean attempt(long msecs)
          Wait at most msecs millisconds for a permit.
 void release()
          Release a permit
 void release(long n)
          Release N permits
 
Methods inherited from class org.metasyntactic.thread.concurrent.Semaphore
permits
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

acquire

public void acquire()
             throws java.lang.InterruptedException
Description copied from class: Semaphore
Wait until a permit is available, and take one

Specified by:
acquire in interface Monitor
Overrides:
acquire in class Semaphore
java.lang.InterruptedException

attempt

public boolean attempt(long msecs)
                throws java.lang.InterruptedException
Description copied from class: Semaphore
Wait at most msecs millisconds for a permit.

Specified by:
attempt in interface Monitor
Overrides:
attempt in class Semaphore
Parameters:
msecs - The number of milliseconds to wait for a permit
Returns:
True/False on whether or not the permit was granted
Throws:
java.lang.InterruptedException

release

public void release()
Description copied from class: Semaphore
Release a permit

Specified by:
release in interface Monitor
Overrides:
release in class Semaphore

release

public void release(long n)
Release N permits

Overrides:
release in class Semaphore
Parameters:
n - The number of permits to release