title: How to force a call to addShutdownHook(...)
body: <p>I want one thread to continuously receive message from kafka and also I want to close executor when I press ctrl+C, but it seems that addShutdownHook(...) method isn't called.</p>
  
  <p>How to make sure it will be called? Thanks very much!</p>
  
  <pre><code>public class wwwwwwww {
      static ExecutorService executor = Executors.newFixedThreadPool(2);
      static {
          Runtime.getRuntime().addShutdownHook(new Thread() {
              public void run() {
                  Logger.getGlobal().info("***************destroying");
                  executor.shutdownNow();
              }
          });
      }
  
      public static void main(String[] args) throws Exception {
          executor.submit(new Runnable() {
              @Override
              public void run() {
                  Logger.getGlobal().info("If you see this log message, then logging is configured correctly and you should see the shutdown hook message.");
                  while (true) {
                      Logger.getGlobal().info("Inside loop");
                      // ConsumerRecords&lt;String, String&gt; records = consumer.poll(100);
                      // for (ConsumerRecord&lt;String, String&gt; record : records) {
                      // System.out.printf("offset = %d, key = %s, value = %s\n", record.offset(), record.key(), record.value());
                      // }
                  }
              }
          });
      }
  }
  </code></pre>