code: public void destroyOnShutdownHook()
      {
          Runtime.getRuntime().addShutdownHook(new Thread()
          {
              @Override
              public void run()
              {
                  try {
                      LifeCycleManager.this.destroy();
                  }
                  catch (Exception e) {
                      System.err.print("Exception in life cycle shutdown handler ");
                      e.printStackTrace(System.err);
                  }
              }
          });
      }
docs: Add a shutdown hook that calls {@link destroy} method