ConcurrentDocumentOperationBlocker { void setMaxConcurrency(int maxConcurrency) { synchronized (monitor) { int deltaConcurrency = maxConcurrency - this.maxConcurrency; if (deltaConcurrency > 0) { semaphore.release(deltaConcurrency); } if (deltaConcurrency < 0) { semaphore.reducePermits(-1 * deltaConcurrency); } this.maxConcurrency = maxConcurrency; } }    }
@Test public void testResizeLarger() throws InterruptedException { spawnThreadPushOperationThenCountDown(); assertFalse(latch.await(10, TimeUnit.MILLISECONDS)); blocker.setMaxConcurrency(3); assertTrue(latch.await(120, TimeUnit.SECONDS)); }