Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
final class PoolService {
  private final ExecutorService pool = Executors.newFixedThreadPool(10);

  public void doSomething() {     
    Future<?> future = pool.submit(new Task());

    // ... 

    try {
      future.get();
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt(); // Reset interrupted status      
    } catch (ExecutionException e) {
      Throwable exception = e.getCause();      
      // Forward to exception reporter
    }
  }  
}

Any Furthermore, any exception that precludes doSomething() from obtaining the Future value can be handled as required.

...