code: private void addShutdownHook() {
      Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
          stopReporting();
          try {
            close();
          } catch (IOException e) {
            log.warn("Unable to close " + this.getClass().getCanonicalName(), e);
          }
        }
      });
    }
docs: Add a shutwon hook that first invokes {@link #stopReporting()} and then closes the {@link RootMetricContext}. This
  ensures all reporting started on the  {@link RootMetricContext} stops properly and any resources obtained by the
  {@link RootMetricContext} are released.