Code example for Semaphore

Methods: acquire

0
 
    private boolean permitAcquired(final long waitTime) throws InterruptedException {
        if (waitTime > 0) {
            return _sem.tryAcquire(waitTime, TimeUnit.MILLISECONDS);
        } else if (waitTime < 0) {
            _sem.acquire();
            return true; 
        } else { 
            return _sem.tryAcquire();
        } 
    } 
 
    /** Clears the pool of all objects. */ 
    protected synchronized void close(){ 
        _closed = true;
        for (T t : _avail)
            cleanup(t);
        _avail.clear();
        _out.clear();
    }