SemaphoreImplpublic class SemaphoreImpl extends Object implements SemaphoreBased 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 void | acquire()
if( Thread.interrupted()) {
throw new InterruptedException();
}
synchronized (this) {
try {
while( numPermits_ <= 0 ) {
wait();
}
numPermits_--;
} catch( InterruptedException ie) {
notify();
throw ie;
}
}
| public synchronized void | release()
numPermits_++;
notify();
|
|