API Overview API Index Package Overview Direct link to this page
JDK 1.6
  java.util.concurrent. Semaphore View Source
Author(s)
Doug Lea
Since
1.5
Version
Serial
Hierarchy
 Object
      Semaphore
Implements
 Serializable
Subclasses
Description
public class Semaphore
  A counting semaphore.
See also:   
Constructors
public Semaphore (int permits)
  Creates a Semaphore with the given number of permits and nonfair fairness setting.
public Semaphore (int permits, boolean fair)
  Creates a Semaphore with the given number of permits and the given fairness setting.
Methods
Hide/Show inherited methods
public void acquire () throws InterruptedException
  Acquires a permit from this semaphore, blocking until one is available, or the thread is interrupted.
public void acquire (int permits) throws InterruptedException
  Acquires the given number of permits from this semaphore, blocking until all are available, or the thread is interrupted.
public void acquireUninterruptibly ()
  Acquires a permit from this semaphore, blocking until one is available.
public void acquireUninterruptibly (int permits)
  Acquires the given number of permits from this semaphore, blocking until all are available.
public int availablePermits ()
  Returns the current number of permits available in this semaphore.
public int drainPermits ()
  Acquires and returns all permits that are immediately available.
protected Collection<Thread> getQueuedThreads ()
  Returns a collection containing threads that may be waiting to acquire.
publicfinal int getQueueLength ()
  Returns an estimate of the number of threads waiting to acquire.
publicfinal boolean hasQueuedThreads ()
  Queries whether any threads are waiting to acquire.
public boolean isFair ()
  Returns true if this semaphore has fairness set true.
protected void reducePermits (int reduction)
  Shrinks the number of available permits by the indicated reduction.
public void release ()
  Releases a permit, returning it to the semaphore.
public void release (int permits)
  Releases the given number of permits, returning them to the semaphore.
public String toString ()
  Returns a string identifying this semaphore, as well as its state.
public boolean tryAcquire ()
  Acquires a permit from this semaphore, only if one is available at the time of invocation.
public boolean tryAcquire (int permits)
  Acquires the given number of permits from this semaphore, only if all are available at the time of invocation.
public boolean tryAcquire (int permits, long timeout, TimeUnit unit) throws InterruptedException
  Acquires the given number of permits from this semaphore, if all become available within the given waiting time and the current thread has not been interrupted.
public boolean tryAcquire (long timeout, TimeUnit unit) throws InterruptedException
  Acquires a permit from this semaphore, if one becomes available within the given waiting time and the current thread has not been interrupted.
Fields
Hide/Show inherited fields
Nested Classes
  Semaphore.Sync
Synchronization implementation for semaphore.
  Semaphore.NonfairSync
NonFair version
  Semaphore.FairSync
Fair version
Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar