Code example for Semaphore

0
    } 
 
 
    SlidingWindow(int itemUnitSize, ItemUnit itemUnit) {
        this.itemUnitSize = itemUnitSize;
        this.semaphore = new Semaphore(this.itemUnitSize);
        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) {