code: public void run() throws Exception {
      try {
  
        CountDownLatch countDownLatch = new CountDownLatch(this.tasks);
        for (int i = 0; i < this.tasks; i++) {
          addTask(i, countDownLatch);
        }
        // Wait for the tasks to finish
        countDownLatch.await();
      } finally {
        try {
          // Calling close() will stop metric reporting
          this.context.close();
        } finally {
          this.executor.shutdownNow();
        }
      }
    }
docs: Run the example.