You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using @EnableScheduling and the executor applicationTaskExecutor the graceful shutdown don't take in account the currently running tasks, when the server shutdown the task is silently aborted (no InteruptedException).
The graceful shutdown wait 1 second before the end of the task, and the log [WARN] - Forcing shutdownNow() - Tasks did not stop in time. is displayed. But no InterruptedException is thrown in the Runnable.
To have an InterruptedException I should create a scheduler like that
ThreadPoolTaskExecutortaskExecutor = newThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(2);
taskExecutor.setMaxPoolSize(2);
taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
taskExecutor.setAwaitTerminationSeconds(1);
taskExecutor.setVirtualThreads(true);
taskExecutor.initialize();
Runtime.getRuntime().addShutdownHook(newThread(() -> {
try {
log.info("Waiting for executor to terminate...");
ThreadPoolExecutorexecutor = taskExecutor.getThreadPoolExecutor();
if (executor != null) {
if (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
log.warn("Forcing shutdownNow() - Tasks did not stop in time.");
executor.shutdownNow();
}
}
} catch (InterruptedExceptione) {
log.error("Shutdown hook interrupted!", e);
Thread.currentThread().interrupt();
}
}));
Doing that the graceful shutdown wait 1 second and stop the task with an InterruptedException.
The goal of the InterruptedException is to be able to log the stopped task, to know that something should be retry.
Why the default ThreadPoolTaskExecutor don't offer a way to have an InterruptedException. Is it possible to add this feature? To avoid to write it manually ?
The text was updated successfully, but these errors were encountered:
Using graceful shutdown with async task ran with
Using
@EnableScheduling
and the executorapplicationTaskExecutor
the graceful shutdown don't take in account the currently running tasks, when the server shutdown the task is silently aborted (no InteruptedException).Using a custom Executor:
The graceful shutdown wait 1 second before the end of the task, and the log
[WARN] - Forcing shutdownNow() - Tasks did not stop in time.
is displayed. But noInterruptedException
is thrown in the Runnable.To have an
InterruptedException
I should create a scheduler like thatDoing that the graceful shutdown wait 1 second and stop the task with an
InterruptedException
.The goal of the
InterruptedException
is to be able to log the stopped task, to know that something should be retry.Why the default
ThreadPoolTaskExecutor
don't offer a way to have anInterruptedException
. Is it possible to add this feature? To avoid to write it manually ?The text was updated successfully, but these errors were encountered: