private void politelyAwaitTermination(CAUSE_FOR_TERMINATION causeForTermination) {
        if (causeForTermination == CAUSE_FOR_TERMINATION.COMPLETED_NORMALLY) {
            return;
        }
        long start = System.currentTimeMillis();
        while (countActiveConsumers() > 0) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                LOG.warn("Thread interrupted while trying to politelyAwaitTermination");
                return;
            }
            long elapsed = System.currentTimeMillis() - start;
            if (pauseOnEarlyTerminationMillis > -1 && elapsed > pauseOnEarlyTerminationMillis) {
                LOG.warn("Waited after an early termination for {}ms, but there was at least one active consumer", elapsed);
                return;
            }
        }
    }
This is used instead of awaitTermination(), because that interrupts
the thread and then waits for its termination.  This politely waits.

@param causeForTermination reason for termination.
tika-batch/src/main/java/org/apache/tika/batch/BatchProcess.java