title: How to stop Callable tasks in Executor service if exception occur
body: <p>I'm trying to implement a sample application to test Callable and ExecutorService interfaces.</p>
  
  <p>In my app I have:</p>
  
  <pre><code>@Bean("fixedThreadPool")
  public ExecutorService fixedThreadPool() {
      return Executors.newFixedThreadPool(5);
  }
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code>public void removeUserIds(Set&lt;String&gt; userIds) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://localhost:8080/remove");
      final List&lt;Callable&lt;String&gt;&gt; callables = new ArrayList&lt;&gt;();  
      userIds.forEach(userId -&gt; {
          final Callable&lt;String&gt; task = () -&gt; callServiceToRemove(builder,userId); //Call to remote service using RestTemplate
          callables.add(task);
      });
  
      try {
          final List&lt;Future&lt;String&gt;&gt; futureList =
              executor.invokeAll(callables);
  
          futureList.forEach(future -&gt; {
              try {
                  log.info(future.get());
              } catch (final Exception e) {
                  log.error("Error : "+ e.getMessage());
              } 
          });
      } catch (final Exception e) {
          log.error("Error Error Error : "+ e.getMessage());
      } finally {
          executor.shutdown();
      }
  }
  </code></pre>
  
  <p>When I am calling removeUserIds() method with 100 userIds, It is working fine in happy flow, but if service is unavailable  or down, error is getting printed 100th time. I am not able to stop/terminate thread if service is unavailable  or down, so further call will not happen to service. 
  Could any one help here to fix this issue, how I can stop thread execution if service is down, or suggest feasible solution here?</p>