@Test public void handlesRejectedExecutionException() { AtomicInteger result = new AtomicInteger(0); ThrottledForwardingExecutor executor = new ThrottledForwardingExecutor( 10, command -> { throw new RejectedExecutionException(); }); executor.execute(result::incrementAndGet); assertEquals(1, result.get()); }
@Override public void execute(Runnable command) { if (availableSlots.tryAcquire()) { try { executor.execute( () -> { command.run(); availableSlots.release(); }); } catch (RejectedExecutionException e) { command.run(); } } else { command.run(); } }
ThrottledForwardingExecutor implements Executor { @Override public void execute(Runnable command) { if (availableSlots.tryAcquire()) { try { executor.execute( () -> { command.run(); availableSlots.release(); }); } catch (RejectedExecutionException e) { command.run(); } } else { command.run(); } } }
ThrottledForwardingExecutor implements Executor { @Override public void execute(Runnable command) { if (availableSlots.tryAcquire()) { try { executor.execute( () -> { command.run(); availableSlots.release(); }); } catch (RejectedExecutionException e) { command.run(); } } else { command.run(); } } ThrottledForwardingExecutor(int maximumConcurrency, Executor executor); }
ThrottledForwardingExecutor implements Executor { @Override public void execute(Runnable command) { if (availableSlots.tryAcquire()) { try { executor.execute( () -> { command.run(); availableSlots.release(); }); } catch (RejectedExecutionException e) { command.run(); } } else { command.run(); } } ThrottledForwardingExecutor(int maximumConcurrency, Executor executor); @Override void execute(Runnable command); }
ThrottledForwardingExecutor implements Executor { @Override public void execute(Runnable command) { if (availableSlots.tryAcquire()) { try { executor.execute( () -> { command.run(); availableSlots.release(); }); } catch (RejectedExecutionException e) { command.run(); } } else { command.run(); } } ThrottledForwardingExecutor(int maximumConcurrency, Executor executor); @Override void execute(Runnable command);  }