in java/clickhouse-client/src/main/java/com/epam/deltix/clickhouse/util/ExecutorsUtil.java [29:80]
public static void shutdownAndAwaitTermination(ExecutorService pool, long timeoutMs) {
String description = String.valueOf(pool);
LOG.debug()
.append("Shutting down executor service @")
.append(description)
.append(". Awaiting termination of scheduled tasks.")
.commit();
pool.shutdown(); // Disable new tasks from being submitted
try {
// Wait a while for existing tasks to terminate
if (!pool.awaitTermination(timeoutMs, TimeUnit.MILLISECONDS)) {
LOG.warn()
.append("Scheduled tasks for executor service @")
.append(description)
.append(" failed to complete in ")
.append(timeoutMs)
.append(" ms. Aborting unfinished tasks.")
.commit();
pool.shutdownNow(); // Cancel currently executing tasks
// Wait a while for tasks to respond to being cancelled
if (!pool.awaitTermination(timeoutMs, TimeUnit.MILLISECONDS)) {
LOG.error()
.append("Scheduled tasks for executor service @")
.append(description)
.append(" failed to interrupt in ")
.append(timeoutMs)
.append(" ms.")
.commit();
}
} else {
LOG.debug()
.append("Successfully terminated executor service @")
.append(description)
.commit();
}
} catch (InterruptedException ie) {
LOG.warn()
.append("Awaiting thread for executor service @")
.append(description)
.append(" was interrupted. Trying to re-cancel unfinished tasks.")
.commit();
// (Re-)Cancel if current thread also interrupted
pool.shutdownNow();
// Preserve interrupt status
Thread.currentThread().interrupt();
}
}