You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "showuon (via GitHub)" <gi...@apache.org> on 2023/02/14 06:47:02 UTC

[GitHub] [kafka] showuon commented on a diff in pull request #13238: KAFKA-14708: Use Java thread instead of kafka library for example purpose

showuon commented on code in PR #13238:
URL: https://github.com/apache/kafka/pull/13238#discussion_r1105357737


##########
examples/src/main/java/kafka/examples/Consumer.java:
##########
@@ -63,33 +63,36 @@ public Consumer(final String topic,
         this.numMessageToConsume = numMessageToConsume;
         this.messageRemaining = numMessageToConsume;
         this.latch = latch;
+        this.isRunning = true;
     }
 
     KafkaConsumer<Integer, String> get() {
         return consumer;
     }
 
     @Override
+    public void run() {
+        try {
+            do {
+                doWork();
+            } while (isRunning && messageRemaining > 0);
+            System.out.println(groupId + " finished reading " + numMessageToConsume + " messages");
+        } catch (Exception ignored) {

Review Comment:
   Why do we ignore this exception? There might be something useful for troubleshooting, right?



##########
examples/src/main/java/kafka/examples/Consumer.java:
##########
@@ -63,33 +63,36 @@ public Consumer(final String topic,
         this.numMessageToConsume = numMessageToConsume;
         this.messageRemaining = numMessageToConsume;
         this.latch = latch;
+        this.isRunning = true;
     }
 
     KafkaConsumer<Integer, String> get() {
         return consumer;
     }
 
     @Override
+    public void run() {
+        try {
+            do {
+                doWork();
+            } while (isRunning && messageRemaining > 0);

Review Comment:
   Why should we need `isRunning`? From the usage, we will wait for 5 mins for the `latch` completed, if not, `TimeoutException` will be thrown, so no other thread will call `shutdown` during it's running. Is my understanding correct? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org