ThrottlingExecutor implements Throttleable, Executor { @Override public void setWorkFactor(double workFactor) { if (workFactor < MIN_WORK_FACTOR) { throw new IllegalArgumentException("Work factor must be >= " + MIN_WORK_FACTOR); } if (workFactor > MAX_WORK_FACTOR) { throw new IllegalArgumentException("Work factor must be <= " + MAX_WORK_FACTOR); } workToIdleFactor = (1.0 - workFactor) / workFactor; } ThrottlingExecutor(long maxDelayMillis);   ThrottlingExecutor(long maxDelayMillis, HighResolutionClock clock); void execute(Runnable command); @Override void setWorkFactor(double workFactor); @Override double getWorkFactor();  }
@Test(expected = IllegalArgumentException.class) public void testLessThan0PercentWorkRate() { new ThrottlingExecutor(MAX_NANOS).setWorkFactor(-0.1); }
@Test(expected = IllegalArgumentException.class) public void testGreaterThan100PercentWorkRate() { new ThrottlingExecutor(MAX_NANOS).setWorkFactor(1.1); }