title: How to shutdown a java executor service only if all threads throw an exception
body: <p>I am using the below code in  a java application.It spawns 3 worker threads. What I need is that if one thread fails (throws an unhandled exception from run)other threads should continue execution. If I call executor.shutdown() as below it is terminating the other threads(no new tasks are accepted).One of the options that I was thinking was  to have a counter on the ExecutionException catch block and call shutdown only when counter==numConsumers. Is there a better way to do this?</p>
  
  <pre><code>    public void execute()  {
                    int numConsumers = Integer.parseInt(configs.getSINK_NUMBER_OF_CONSUMERs());
  Future&lt;?&gt; future=null;
                    log.info("Creating {}  consumers",numConsumers);
                    List&lt;String&gt; topics = Arrays.asList(configs.getTOPIC_NAME());
                    ExecutorService executor = Executors.newFixedThreadPool(numConsumers);
                    final List&lt;SinkConsumer&gt; consumers = new ArrayList&lt;&gt;();
                    for (int i = 0; i &lt; numConsumers; i++) {
                      consumer = new SinkConsumer(UUID.randomUUID().toString(),topics,configs);
                      consumers.add(consumer);
                      future =  executor.submit(consumer);
                    }
              try {
                           future.get();
                       } catch (InterruptedException e) {
                           Thread.currentThread().interrupt();
                       } catch (ExecutionException e) {
                           executor.shutdown();
                       }
              }
  </code></pre>