From ff0bddc11472768fb63c93f178c1a7b235f13019 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 4 Nov 2022 11:01:21 +0100 Subject: [PATCH] WIP:TaskExecutor-NEU --- src/main/java/de/juplo/kafka/Application.java | 11 ++++++++--- .../java/de/juplo/kafka/ApplicationConfiguration.java | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/juplo/kafka/Application.java b/src/main/java/de/juplo/kafka/Application.java index a9b466d..705f52f 100644 --- a/src/main/java/de/juplo/kafka/Application.java +++ b/src/main/java/de/juplo/kafka/Application.java @@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import javax.annotation.PreDestroy; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; @@ -19,17 +19,19 @@ import java.util.concurrent.Future; public class Application implements ApplicationRunner { @Autowired - Executor executor; + ExecutorService executorService; @Autowired Consumer kafkaConsumer; @Autowired SimpleConsumer simpleConsumer; + Future consumerJob; + @Override public void run(ApplicationArguments args) throws Exception { log.info("Starting SimpleConsumer"); - executor.execute(simpleConsumer); + consumerJob = executorService.submit(simpleConsumer); } @PreDestroy @@ -37,6 +39,9 @@ public class Application implements ApplicationRunner { log.info("Signaling SimpleConsumer to quit its work"); kafkaConsumer.wakeup(); + log.info("Waiting for SimpleConsumer to finish its work"); + consumerJob.get(); + log.info("SimpleConsumer finished its work"); } diff --git a/src/main/java/de/juplo/kafka/ApplicationConfiguration.java b/src/main/java/de/juplo/kafka/ApplicationConfiguration.java index de77c60..16926fd 100644 --- a/src/main/java/de/juplo/kafka/ApplicationConfiguration.java +++ b/src/main/java/de/juplo/kafka/ApplicationConfiguration.java @@ -8,6 +8,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.kafka.core.ConsumerFactory; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + @Configuration @EnableConfigurationProperties({ KafkaProperties.class, ApplicationProperties.class }) -- 2.20.1