FileDocCategorySizeDatePackage
SemaphoreImpl.javaAPI DocGlassfish v2 API2796Fri May 04 22:32:08 BST 2007com.sun.enterprise.util

SemaphoreImpl

public class SemaphoreImpl extends Object implements Semaphore
Based on Concurrent Programming in Java, Second Edition, by Doug Lea, page 266

Fields Summary
private long
numPermits_
Constructors Summary
public SemaphoreImpl(long initialPermits)

        numPermits_ = initialPermits;
    
Methods Summary
public voidacquire()

        if( Thread.interrupted()) {
            throw new InterruptedException();
        }
        
        synchronized (this) {
            try {
                while( numPermits_ <= 0 ) {
                    wait();
                } 
                numPermits_--;
            } catch( InterruptedException ie) {
                notify();
                throw ie;
            }
        }
    
public synchronized voidrelease()

        numPermits_++;
        notify();