// Shut down the executor service
ScheduledExecutorService executor = context.getExecutor();
executor.shutdown();
try {
// Wait for all remaining background threads to terminate
if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
log.warn("Attempting to forcibly shutdown runaway threads");
executor.shutdownNow();
}
} catch (InterruptedException e) {
log.warn("Interrupted while waiting for background threads", e);