kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject [kafka] branch 1.0 updated: MINOR: Make PushHttpMetricsReporter use daemon threads.
Date Fri, 02 Mar 2018 21:16:35 GMT
This is an automated email from the ASF dual-hosted git repository.

ewencp pushed a commit to branch 1.0
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/1.0 by this push:
     new 73fb1bf  MINOR: Make PushHttpMetricsReporter use daemon threads.
73fb1bf is described below

commit 73fb1bffe160be243aa4e451416fcc101c16f78b
Author: Ewen Cheslack-Postava <me@ewencp.org>
AuthorDate: Fri Mar 2 13:16:21 2018 -0800

    MINOR: Make PushHttpMetricsReporter use daemon threads.
    
    This is a safe guard against users that do not properly close() the reporter, which causes
    the process to hang even if its main() method returns. This was the case with Kafka Streams
    apps in some cases in Kafka < 1.1.0 (KAFKA-6383). Without this fix, this behavior can
make
    it difficult to use this class in some types of system tests.
    
    Author: Ewen Cheslack-Postava <me@ewencp.org>
    
    Reviewers: Guozhang Wang <wangguoz@gmail.com>, Ismael Juma <ismael@juma.me.uk>
    
    Closes #4629 from ewencp/http-metrics-dont-block-shutdown
---
 .../org/apache/kafka/tools/PushHttpMetricsReporter.java    | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/src/main/java/org/apache/kafka/tools/PushHttpMetricsReporter.java b/tools/src/main/java/org/apache/kafka/tools/PushHttpMetricsReporter.java
index c5764b4..64168b6 100644
--- a/tools/src/main/java/org/apache/kafka/tools/PushHttpMetricsReporter.java
+++ b/tools/src/main/java/org/apache/kafka/tools/PushHttpMetricsReporter.java
@@ -48,6 +48,8 @@ import java.util.Map;
 import java.util.Scanner;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -96,7 +98,17 @@ public class PushHttpMetricsReporter implements MetricsReporter {
 
     public PushHttpMetricsReporter() {
         time = new SystemTime();
-        executor = Executors.newSingleThreadScheduledExecutor();
+        executor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
+            @Override
+            public Thread newThread(Runnable r) {
+                Thread thread = Executors.defaultThreadFactory().newThread(r);
+                thread.setName("PushHttpMetricsReporterThread");
+                // Ensure these are daemon threads so they won't block shutdown if the MetricsReporter
is not properly
+                // closed (e.g. as might happen with Kafka Streams < 1.1.0)
+                thread.setDaemon(true);
+                return thread;
+            }
+        });
     }
 
     PushHttpMetricsReporter(Time mockTime, ScheduledExecutorService mockExecutor) {

-- 
To stop receiving notification emails like this one, please contact
ewencp@apache.org.

Mime
View raw message