You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by ti...@apache.org on 2023/03/29 02:36:32 UTC

[pulsar] branch master updated: [fix][test] Shutdown executor on PerformanceProducer closed (#19926)

This is an automated email from the ASF dual-hosted git repository.

tison pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new d8774671f5d [fix][test] Shutdown executor on PerformanceProducer closed (#19926)
d8774671f5d is described below

commit d8774671f5d52be4ef940ea894ba4f9b1f5717f9
Author: StevenLuMT <ls...@126.com>
AuthorDate: Wed Mar 29 10:36:23 2023 +0800

    [fix][test] Shutdown executor on PerformanceProducer closed (#19926)
    
    Co-authored-by: lushiji <lu...@didiglobal.com>
---
 .../org/apache/pulsar/testclient/PerformanceProducer.java   | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceProducer.java b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceProducer.java
index 9aedc8c4bd3..0c56f1d5c73 100644
--- a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceProducer.java
+++ b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceProducer.java
@@ -356,6 +356,7 @@ public class PerformanceProducer {
         long start = System.nanoTime();
 
         Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            executorShutdownNow();
             printAggregatedThroughput(start, arguments);
             printAggregatedStats();
         }));
@@ -481,6 +482,18 @@ public class PerformanceProducer {
         }
     }
 
+    private static void executorShutdownNow() {
+        executor.shutdownNow();
+        try {
+            if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
+                log.warn("Failed to terminate executor within timeout. The following are stack"
+                        + " traces of still running threads.");
+            }
+        } catch (InterruptedException e) {
+            log.warn("Shutdown of thread pool was interrupted");
+        }
+    }
+
     static IMessageFormatter getMessageFormatter(String formatterClass) {
         try {
             ClassLoader classLoader = PerformanceProducer.class.getClassLoader();