Code example for Semaphore

Methods: tryAcquire

0
        this.itemUnit = itemUnit;
    } 
 
 
    public boolean tryAcquireByLength(int lenth) {
        return this.semaphore.tryAcquire(this.covertToItemLength(lenth));
    } 
 
 
    public boolean tryAcquireByLength(int length, long timeout, TimeUnit unit) throws InterruptedException {
        return this.semaphore.tryAcquire(this.covertToItemLength(length), timeout, unit);
    } 
 
 
    public void releaseByLenth(int length) {
        this.semaphore.release(this.covertToItemLength(length));
    } 
 
 
    public int getWindowsSize() { 
        return itemUnitSize;