Source:
<code>public void changingMaxWorkersMeetsConcurrencyGoalsTest() throws InterruptedException, TimeoutException { final int numBusyWorkers = 2; SharedExecutorPool sharedPool = new SharedExecutorPool("ChangingMaxWorkersMeetsConcurrencyGoalsTest"); final AtomicInteger notifiedMaxPoolSize = new AtomicInteger(); LocalAwareExecutorService executor = sharedPool.newExecutor(0, notifiedMaxPoolSize::set, 4, "internal", "resizetest"); AtomicBoolean stayBusy = new AtomicBoolean(true); Semaphore busyWorkerPermits = new Semaphore(numBusyWorkers); Thread makeBusy = new Thread(() -> { <START> while (stayBusy.get() == true) <END> { try { if (busyWorkerPermits.tryAcquire(1, MILLISECONDS)) { executor.execute(new BusyWork(busyWorkerPermits)); } } catch (InterruptedException e) { } } }); makeBusy.start(); try { for (int repeat = 0; repeat < 1000; repeat++) { assertMaxTaskConcurrency(executor, 1); Assert.assertEquals(1, notifiedMaxPoolSize.get()); assertMaxTaskConcurrency(executor, 2); Assert.assertEquals(2, notifiedMaxPoolSize.get()); assertMaxTaskConcurrency(executor, 1); Assert.assertEquals(1, notifiedMaxPoolSize.get()); assertMaxTaskConcurrency(executor, 3); Assert.assertEquals(3, notifiedMaxPoolSize.get()); executor.setMaximumPoolSize(0); Assert.assertEquals(0, notifiedMaxPoolSize.get()); assertMaxTaskConcurrency(executor, 4); Assert.assertEquals(4, notifiedMaxPoolSize.get()); } } finally { stayBusy.set(false); makeBusy.join(TimeUnit.SECONDS.toNanos(5)); Assert.assertFalse(makeBusy.isAlive()); sharedPool.shutdownAndWait(1L, MINUTES); } }</code><technical_language>nit: while (stayBusy.get())</technical_language>

Target:
public void changingMaxWorkersMeetsConcurrencyGoalsTest() throws InterruptedException, TimeoutException { final int numBusyWorkers = 2; SharedExecutorPool sharedPool = new SharedExecutorPool("ChangingMaxWorkersMeetsConcurrencyGoalsTest"); final AtomicInteger notifiedMaxPoolSize = new AtomicInteger(); LocalAwareExecutorService executor = sharedPool.newExecutor(0, notifiedMaxPoolSize::set, 4, "internal", "resizetest"); AtomicBoolean stayBusy = new AtomicBoolean(true); Semaphore busyWorkerPermits = new Semaphore(numBusyWorkers); Thread makeBusy = new Thread(() -> { while (stayBusy.get() == true) { try { if (busyWorkerPermits.tryAcquire(1, MILLISECONDS)) { executor.execute(new BusyWork(busyWorkerPermits)); } } catch (InterruptedException e) { } } }); makeBusy.start(); try { for (int repeat = 0; repeat < 1000; repeat++) { assertMaxTaskConcurrency(executor, 1); Assert.assertEquals(1, notifiedMaxPoolSize.get()); assertMaxTaskConcurrency(executor, 2); Assert.assertEquals(2, notifiedMaxPoolSize.get()); assertMaxTaskConcurrency(executor, 1); Assert.assertEquals(1, notifiedMaxPoolSize.get()); assertMaxTaskConcurrency(executor, 3); Assert.assertEquals(3, notifiedMaxPoolSize.get()); executor.setMaximumPoolSize(0); Assert.assertEquals(0, notifiedMaxPoolSize.get()); assertMaxTaskConcurrency(executor, 4); Assert.assertEquals(4, notifiedMaxPoolSize.get()); } } finally { stayBusy.set(false); makeBusy.join(TimeUnit.SECONDS.toMillis(5)); Assert.assertFalse("makeBusy thread should have checked stayBusy and exited", makeBusy.isAlive()); sharedPool.shutdownAndWait(1L, MINUTES); } }