BlockingSemaphore(long permits) { checkNotNegative(permits); this.currentPermits = permits; }
@Test(expected = IllegalArgumentException.class) public void testNegative() { Semaphore64 semaphore = new BlockingSemaphore(1); semaphore.acquire(-1); }
outstandingElementCount = null; } else if (settings.getLimitExceededBehavior() == FlowController.LimitExceededBehavior.Block) { outstandingElementCount = new BlockingSemaphore(maxOutstandingElementCount); } else { outstandingElementCount = new NonBlockingSemaphore(maxOutstandingElementCount); outstandingByteCount = null; } else if (settings.getLimitExceededBehavior() == FlowController.LimitExceededBehavior.Block) { outstandingByteCount = new BlockingSemaphore(maxOutstandingRequestBytes); } else { outstandingByteCount = new NonBlockingSemaphore(maxOutstandingRequestBytes);
outstandingElementCount = null; } else if (settings.getLimitExceededBehavior() == FlowController.LimitExceededBehavior.Block) { outstandingElementCount = new BlockingSemaphore(maxOutstandingElementCount); } else { outstandingElementCount = new NonBlockingSemaphore(maxOutstandingElementCount); outstandingByteCount = null; } else if (settings.getLimitExceededBehavior() == FlowController.LimitExceededBehavior.Block) { outstandingByteCount = new BlockingSemaphore(maxOutstandingRequestBytes); } else { outstandingByteCount = new NonBlockingSemaphore(maxOutstandingRequestBytes);
BlockingSemaphore(long permits) { checkNotNegative(permits); this.currentPermits = permits; }
@Test public void testBlocking() throws InterruptedException { final Semaphore64 semaphore = new BlockingSemaphore(1); semaphore.acquire(1);
public synchronized void release(long permits) { checkNotNegative(permits); currentPermits += permits; notifyAll(); }
public synchronized void release(long permits) { checkNotNegative(permits); currentPermits += permits; notifyAll(); }
public synchronized boolean acquire(long permits) { checkNotNegative(permits); boolean interrupted = false; while (currentPermits < permits) { try { wait(); } catch (InterruptedException e) { interrupted = true; } } currentPermits -= permits; if (interrupted) { Thread.currentThread().interrupt(); } return true; } }
public synchronized boolean acquire(long permits) { checkNotNegative(permits); boolean interrupted = false; while (currentPermits < permits) { try { wait(); } catch (InterruptedException e) { interrupted = true; } } currentPermits -= permits; if (interrupted) { Thread.currentThread().interrupt(); } return true; } }