WIP:TaskExecutor-NEU
authorKai Moritz <kai@juplo.de>
Fri, 4 Nov 2022 10:01:21 +0000 (11:01 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 4 Nov 2022 11:52:13 +0000 (12:52 +0100)
src/main/java/de/juplo/kafka/Application.java
src/main/java/de/juplo/kafka/ApplicationConfiguration.java

index a9b466d..705f52f 100644 (file)
@@ -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");
   }
 
 
index de77c60..16926fd 100644 (file)
@@ -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 })