BlockingThreadPoolExecutorService extends ForwardingListeningExecutorService { @Override public <T> ListenableFuture<T> submit(Callable<T> task) { try { queueingPermits.acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return Futures.immediateFailedCheckedFuture(e); } return super.submit(new CallableWithPermitRelease<T>(task)); } BlockingThreadPoolExecutorService(int activeTasks, int waitingTasks,
      long keepAliveTime, TimeUnit unit, String prefixName); static ThreadFactory getNamedThreadFactory(final String prefix); @Override ListenableFuture<T> submit(Callable<T> task); @Override ListenableFuture<T> submit(Runnable task, T result); @Override ListenableFuture<?> submit(Runnable task); @Override void execute(Runnable command); @Override List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks); @Override List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
      long timeout, TimeUnit unit); @Override T invokeAny(Collection<? extends Callable<T>> tasks); @Override T invokeAny(Collection<? extends Callable<T>> tasks, long timeout,
      TimeUnit unit);  }
@Test public void testSubmitCallable() throws Exception { ensureCreated(); ListenableFuture<Integer> f = tpe.submit(callableSleeper); Integer v = f.get(); assertEquals(SOME_VALUE, v); }
@Test public void testSubmitRunnable() throws Exception { ensureCreated(); int totalTasks = NUM_ACTIVE_TASKS + NUM_WAITING_TASKS; StopWatch stopWatch = new StopWatch().start(); for (int i = 0; i < totalTasks; i++) { tpe.submit(sleeper); assertDidntBlock(stopWatch); } tpe.submit(sleeper); assertDidBlock(stopWatch); }