1 23 package com.sun.enterprise.util; 24 25 30 31 public class SemaphoreImpl implements Semaphore { 32 33 private long numPermits_; 34 35 public SemaphoreImpl(long initialPermits) { 36 numPermits_ = initialPermits; 37 } 38 39 public synchronized void release() { 40 numPermits_++; 41 notify(); 42 } 43 44 public void acquire() throws InterruptedException { 45 if( Thread.interrupted()) { 46 throw new InterruptedException (); 47 } 48 49 synchronized (this) { 50 try { 51 while( numPermits_ <= 0 ) { 52 wait(); 53 } 54 numPermits_--; 55 } catch( InterruptedException ie) { 56 notify(); 57 throw ie; 58 } 59 } 60 } 61 62 } 63 | Popular Tags |