void () { if (INDEX_WRITING_POOL.isEmpty()) { return; } List<Future<?>> futures = new ArrayList<>(INDEX_WRITING_POOL.size()); INDEX_WRITING_POOL.forEach(executor -> futures.add(executor.submit(EmptyRunnable.getInstance()))); var startTime = System.currentTimeMillis(); while (!futures.isEmpty()) { for (var iterator = futures.iterator(); iterator.hasNext(); ) { var future = iterator.next(); if (future.isDone()) { iterator.remove(); } } TimeoutUtil.sleep(10); if (System.currentTimeMillis() - startTime > WRITERS_SHUTDOWN_WAITING_TIME_MS) { var queueSize = INDEX_WRITES_QUEUED.get(); var errorMessage = "Failed to shutdown index writers, queue size: " + queueSize + "; executors active: " + futures; if (queueSize == 0) { LOG.warn(errorMessage); } else { LOG.error(errorMessage); } return; } } }