code: private void awaitTasks() {
          if (_tasksPending.get() == 0) {
              return;
          }
          synchronized (this) {
              while (_tasksPending.get() != 0) {
                  try {
                      logger.info("Scan tasks still pending, waiting");
                      wait();
                  } catch (final InterruptedException e) {
                      logger.debug("Interrupted while awaiting task completion", e);
                  }
              }
          }
      }
docs: Waits for all pending tasks to finish