title: How to call shutdown on an ExecutorService that has been supplied to a CompletableFuture?
body: <p>I am running a batch job every 15 minutes, where I get records for 5 different events and push them out to an API to eventually go out as Push Notifications on a mobile device.</p>
  <p>I am using Java 8, Spring boot application with Quartz scheduler.</p>
  <p>I have a service class which reads the different event types from a property file and loops over those and creates 5 different controllers via a Factory to handle each of these 5 events.</p>
  <p>My question is where do I call executor.shutdown to shutdown the ExecutorService?</p>
  <p>Here is the basic structure of my program:</p>
  <pre><code> public class ServiceImpl {
  
      ExecutorService executor = Executors.newFixedThreadPool(10);
  
      for (Event event: eventTypes)
          
          
          EventController eventController = eventFactory.createEventController(event);
          eventController.executeTasks(executor);
                  
          
      }
  }
  
  
  public interface EventController {
      
      EventBean executeTasks(ExecutorService executor);
      
      EventBean transform1();
      EventBean transform2(); 
  }
  
  
  
  public class EventController1 implements EventController {
  
  
  
      public EventBean executeTasks(ExecutorService executor) {
  
  
          CompletableFuture&lt;List&lt;Event1&gt;&gt; cf1 = CompletableFuture.supplyAsync(() -&gt; {
                          
                  //db call 1
                                          
          }, executor);
                  
                  
          CompletableFuture&lt;EventBean1&gt; combinedFuture = cf1
                  .thenCombineAsync(() -&gt; {
  
                  //db call 2, independent from 1, hence called async
  
          });
  
          combinedFuture
          .thenApply(e -&gt; transform1())
          .thenApply(e -&gt; transform2())
  
      }   
  
  }
  
  
  public class EventController2 implements EventController {
  
  
  
      public EventBean executeTasks(ExecutorService executor) {
  
  
          CompletableFuture&lt;List&lt;Event2&gt;&gt; cf1 = CompletableFuture.supplyAsync(() -&gt; {
                          
                  //db call 1
                                          
          }, executor);
                  
                  
          CompletableFuture&lt;EventBean1&gt; combinedFuture = cf1
                  .thenCombineAsync(() -&gt; {
  
                  //db call 2, independent from 1, hence called async
  
          });
  
          combinedFuture
          .thenApply(e -&gt; transform1())
          .thenApply(e -&gt; transform2())
  
      }   
  
  }
  
  
  public class EventController3 implements EventController {
  
  
  
      public EventBean executeTasks(ExecutorService executor) {
  
  
          CompletableFuture&lt;List&lt;Event3&gt;&gt; cf1 = CompletableFuture.supplyAsync(() -&gt; {
                          
                 //db call 1
                                          
          }, executor);
                  
                  
          CompletableFuture&lt;EventBean1&gt; combinedFuture = cf1
                  .thenCombineAsync(() -&gt; {
  
                  //db call 2, independent from 1, hence called async
  
          });
  
          combinedFuture
          .thenApply(e -&gt; transform1())
          .thenApply(e -&gt; transform2())
  
      }   
  
  }
  </code></pre>