com.echomine.util
Class Semaphore

java.lang.Object
  extended by com.echomine.util.Semaphore
All Implemented Interfaces:
Sync

public class Semaphore
extends java.lang.Object
implements Sync

A semaphore is a old locking technique where only a specified number of threads can obtain the lock at one time. The other threads that wants to acquire the lock will wait in line until the lock is released. Everyone takes turns obtaining the lock. The number of locks that can be acquired at one time is determined by the constructor. This class does not guarantee that a thread waiting to obtain a lock will get it, even if it is waiting for it before other threads. There is no Priority assigned to the waiting.


Field Summary
protected  long permits
           
 
Constructor Summary
Semaphore(long initial)
           
 
Method Summary
 void acquire()
           
 boolean attempt(long msecs)
           
 void release()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

permits

protected long permits
Constructor Detail

Semaphore

public Semaphore(long initial)
Method Detail

acquire

public void acquire()
             throws java.lang.InterruptedException
Specified by:
acquire in interface Sync
Throws:
java.lang.InterruptedException

release

public void release()
Specified by:
release in interface Sync

attempt

public boolean attempt(long msecs)
                throws java.lang.InterruptedException
Specified by:
attempt in interface Sync
Throws:
java.lang.InterruptedException


Copyright © 2001-2005 Echomine. All Rights Reserved.