org.apache.avalon.excalibur.concurrent
Class Semaphore

java.lang.Object
  |
  +--org.apache.avalon.excalibur.concurrent.Semaphore
All Implemented Interfaces:
Sync
Direct Known Subclasses:
Mutex

Deprecated. use EDU.oswego.cs.dl.util.concurrent.Semaphore instead

public class Semaphore
extends Object
implements Sync

This class implements a counting semaphore, also known as a Dijkstra semaphore. A semaphore is used to control access to resources. A counting semaphore has a count associated with it and each acquire() call reduces the count. A thread that tries to acquire() a semaphore with a zero count blocks until someone else calls release(), which increases the count.

Since:
4.0
Version:
CVS $Revision: 1.4 $ $Date: 2003/03/22 12:46:23 $

Constructor Summary
Semaphore(long tokens)
          Deprecated. Creates a semaphore with the specified number of tokens, which determines the maximum number of acquisitions to allow.
 
Method Summary
 void acquire()
          Deprecated. Aquire access to resource.
 boolean attempt(long msecs)
          Deprecated. Aquire access to resource.
 void release()
          Deprecated. Release lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Semaphore

public Semaphore(long tokens)
Deprecated. 
Creates a semaphore with the specified number of tokens, which determines the maximum number of acquisitions to allow.

Parameters:
tokens - the maximum number of acquisitions to allow
Method Detail

acquire

public void acquire()
             throws InterruptedException
Deprecated. 
Description copied from interface: Sync
Aquire access to resource. This method will block until resource aquired.

Specified by:
acquire in interface Sync
Throws:
InterruptedException - if an error occurs

release

public void release()
Deprecated. 
Description copied from interface: Sync
Release lock.

Specified by:
release in interface Sync

attempt

public boolean attempt(long msecs)
                throws InterruptedException
Deprecated. 
Description copied from interface: Sync
Aquire access to resource. This method will block for a maximum of msec.

Specified by:
attempt in interface Sync
Parameters:
msecs - the duration to wait for lock to be released
Returns:
true if lock aquired, false on timeout
Throws:
InterruptedException - if an error occurs


Copyright © 2000-2003 Apache Jakarta Project. All Rights Reserved.