public void start() {
    // unsupported if null
    if (tenuredGenPool == null) {
      return;
    }
    MemoryMXBean mxBean = ManagementFactory.getMemoryMXBean();
    NotificationEmitter emitter = (NotificationEmitter) mxBean;
    notificationListener = (n, hb) -> {
      if (n.getType().equals(
        MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
        long maxMemory = tenuredGenPool.getUsage().getMax();
        long usedMemory = tenuredGenPool.getUsage().getUsed();
        for (Listener listener : listeners) {
          listener.memoryUsageAboveThreshold(usedMemory, maxMemory);
        }
      }
    };
    emitter.addNotificationListener(notificationListener, null, null);
  }
Class that monitors memory usage and notifies the listeners when a certain of threshold of memory is used
after GC (collection usage).
common/src/java/org/apache/hadoop/hive/common/HeapMemoryMonitor.java