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

[pulsar] branch branch-2.9 updated: [fix][client] Fix IllegalThreadStateException when using newThread in ExecutorProvider.ExtendedThreadFactory

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

zhaocong pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.9 by this push:
     new 7f5e83771dc [fix][client] Fix IllegalThreadStateException when using newThread in ExecutorProvider.ExtendedThreadFactory
7f5e83771dc is described below

commit 7f5e83771dc648acfdd64cd3faac7e68a8d4f570
Author: Cong Zhao <zh...@apache.org>
AuthorDate: Tue Nov 1 12:47:42 2022 +0800

    [fix][client] Fix IllegalThreadStateException when using newThread in ExecutorProvider.ExtendedThreadFactory
    
    (cherry picked from commit eaad1940fdbfe4d4324e267047b9164fafc091fb)
---
 .../main/java/org/apache/pulsar/client/util/ExecutorProvider.java    | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/util/ExecutorProvider.java b/pulsar-client/src/main/java/org/apache/pulsar/client/util/ExecutorProvider.java
index 5cacd845069..c70894e2525 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/util/ExecutorProvider.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/util/ExecutorProvider.java
@@ -42,7 +42,7 @@ public class ExecutorProvider {
 
     public static class ExtendedThreadFactory extends DefaultThreadFactory {
         @Getter
-        private Thread thread;
+        private volatile Thread thread;
         public ExtendedThreadFactory(String poolName) {
             super(poolName, false);
         }
@@ -52,9 +52,10 @@ public class ExecutorProvider {
 
         @Override
         public Thread newThread(Runnable r) {
-            thread = super.newThread(r);
+            Thread thread = super.newThread(r);
             thread.setUncaughtExceptionHandler((t, e) ->
                     log.error("Thread {} got uncaught Exception", t.getName(), e));
+            this.thread = thread;
             return thread;
         }
     }