|
82 | 82 | public class KernelLifecycle {
|
83 | 83 | private static final Logger logger = LogManager.getLogger(KernelLifecycle.class);
|
84 | 84 | private static final int EXECUTOR_SHUTDOWN_TIMEOUT_SECONDS = 30;
|
| 85 | + private static final int EXECUTOR_SERVICE_SHUTDOWN_TIMEOUT_SECONDS = 5; |
85 | 86 | // Enum for provision policy will exist in common library package
|
86 | 87 | // This will be done as part of re-provisioning
|
87 | 88 | // TODO: Use the enum from common library when available
|
@@ -523,10 +524,14 @@ public void shutdown(int timeoutSeconds) {
|
523 | 524 | logger.atInfo().setEventType("executor-service-shutdown-initiated").log();
|
524 | 525 | });
|
525 | 526 | logger.atInfo().log("Waiting for executors to shutdown");
|
526 |
| - boolean executorTerminated = executorService.awaitTermination(timeoutSeconds, |
527 |
| - TimeUnit.SECONDS); |
528 |
| - boolean scheduledExecutorTerminated = scheduledExecutorService.awaitTermination(timeoutSeconds, |
529 |
| - TimeUnit.SECONDS); |
| 527 | + // when kernel shuts down due to external signal, give some time for executor service to stop so that |
| 528 | + // threads are interrupted correctly |
| 529 | + int executorServiceShutdownTimeoutSecond = |
| 530 | + timeoutSeconds == -1 ? EXECUTOR_SERVICE_SHUTDOWN_TIMEOUT_SECONDS : timeoutSeconds; |
| 531 | + boolean executorTerminated = |
| 532 | + executorService.awaitTermination(executorServiceShutdownTimeoutSecond, TimeUnit.SECONDS); |
| 533 | + boolean scheduledExecutorTerminated = |
| 534 | + scheduledExecutorService.awaitTermination(executorServiceShutdownTimeoutSecond, TimeUnit.SECONDS); |
530 | 535 | logger.atInfo("executor-service-shutdown-complete")
|
531 | 536 | .kv("executor-terminated", executorTerminated)
|
532 | 537 | .kv("scheduled-executor-terminated", scheduledExecutorTerminated).log();
|
|
0 commit comments