private void runWithCountAndTimeLogging(final Supplier<Integer> action,
                                            final AtomicInteger totalCount,
                                            final String messageTemplate) {

        final Integer count;
        if (LOGGER.isInfoEnabled()) {
            final Instant startTime = Instant.now();
            count = action.get();
            if (count > 0) {
                try {
                    LOGGER.info("{} - " + messageTemplate + " in {}",
                            TASK_NAME,
                            count,
                            Duration.between(startTime, Instant.now()));
                } catch (final RuntimeException e) {
                    LOGGER.error("Error logging message - messageTemplate: '{}', error: {}",
                            messageTemplate,
                            e.getMessage(),
                            e);
                }
            }
        } else {
            count = action.get();
        }
        totalCount.addAndGet(count);
    }
Synchronised as we don't want to run more than once concurrently.
stroom-processor/stroom-processor-impl-db/src/main/java/stroom/processor/impl/db/ProcessorTaskDeleteExecutorImpl.java