code: public static ExecutorService createFixedTimeoutRethrowingExecutorService(
          int poolSize, long keepAliveTime, TimeUnit timeUnit, 
          final boolean rethrowCancellation)
      {
          ThreadPoolExecutor e = 
              new ThreadPoolExecutor(poolSize, poolSize,
                  keepAliveTime, timeUnit, new LinkedBlockingQueue<Runnable>())
          {
              @Override
              protected void afterExecute(Runnable r, Throwable t)
              {
                  super.afterExecute(r, t);
                  if (t == null && r instanceof Future<?>)
                  {
                      try
                      {
                          Future<?> future = (Future<?>) r;
                          if (future.isDone())
                          {
                              future.get();
                          }
                      }
                      catch (CancellationException ce)
                      {
                          if (rethrowCancellation)
                          {
                              t = ce;
                          }
                      }
                      catch (ExecutionException ee)
                      {
                          t = ee.getCause();
                      }
                      catch (InterruptedException ie)
                      {
                          Thread.currentThread().interrupt();
                      }
                  }
                  if (t != null)
                  {
                      throw new RuntimeException(t);
                  }
              }
          };
          e.allowCoreThreadTimeOut(true);
          return e;
      }
docs: Creates an executor service with a fixed pool size, that will time
  out after a certain period of inactivity.<br>
  <br>
  The executor service will re-throw exceptions that happen in
  any of the tasks that it executes.
  
  @param poolSize The core- and maximum pool size
  @param keepAliveTime The keep alive time
  @param timeUnit The time unit
  @param rethrowCancellation Whether CancellationExceptions should
  also be re-thrown
  @return The executor service