TMP:test:FIX
[demos/kafka/chat] / src / main / java / de / juplo / kafka / chat / backend / implementation / kafka / KafkaServicesThreadPoolTaskExecutorCustomizer.java
1 package de.juplo.kafka.chat.backend.implementation.kafka;
2
3 import lombok.extern.slf4j.Slf4j;
4 import org.springframework.boot.task.ThreadPoolTaskExecutorCustomizer;
5 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
6
7
8 /**
9  * Customizer for the auto-configured Bean {@code applicationTaskExecutor}.
10  *
11  * This customization is necessary, because otherwise, the bean is part
12  * of the lowest phase of the {@link org.springframework.context.SmartLifecycle}
13  * and, hence, destroyed first during shutdown.
14  *
15  * Without this customization, the shutdown of the thread-pool, that is triggered
16  * this way does not succeed, blocking the furthershutdown for 30 seconds.
17  */
18 @Slf4j
19 public class KafkaServicesThreadPoolTaskExecutorCustomizer implements ThreadPoolTaskExecutorCustomizer
20 {
21   @Override
22   public void customize(ThreadPoolTaskExecutor taskExecutor)
23   {
24     log.info("Customizing the auto-configured ThreadPoolTaskExecutor");
25     taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
26     taskExecutor.setAwaitTerminationSeconds(10);
27   }
28 }