You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by xy...@apache.org on 2023/05/26 00:25:58 UTC

[helix] branch master updated: Simplify thread naming in TaskStateModelFactory" (#2507)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3ff103389 Simplify thread naming in TaskStateModelFactory" (#2507)
3ff103389 is described below

commit 3ff1033891511e8b15b4a2bd3f2338c5efb6dba3
Author: Komal Desai <98...@users.noreply.github.com>
AuthorDate: Thu May 25 17:25:53 2023 -0700

    Simplify thread naming in TaskStateModelFactory" (#2507)
    
    Simplify thread naming in TaskStateModelFactory.
    
    ---------
    
    Co-authored-by: Komal Desai <kd...@kdesai-mn1.linkedin.biz>
---
 .../java/org/apache/helix/task/TaskStateModelFactory.java   | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/helix-core/src/main/java/org/apache/helix/task/TaskStateModelFactory.java b/helix-core/src/main/java/org/apache/helix/task/TaskStateModelFactory.java
index 7b9dd74e1..b8474b792 100644
--- a/helix-core/src/main/java/org/apache/helix/task/TaskStateModelFactory.java
+++ b/helix-core/src/main/java/org/apache/helix/task/TaskStateModelFactory.java
@@ -25,10 +25,10 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.atomic.AtomicInteger;
 import javax.management.JMException;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import org.apache.helix.HelixException;
 import org.apache.helix.HelixManager;
 import org.apache.helix.SystemPropertyKeys;
@@ -45,7 +45,6 @@ import org.apache.helix.zookeeper.impl.factory.SharedZkClientFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
  * Factory class for {@link TaskStateModel}.
  */
@@ -191,13 +190,7 @@ public class TaskStateModelFactory extends StateModelFactory<TaskStateModel> {
     LOG.info(
         "Obtained target thread pool size: {} from cluster {} for instance {}. Creating thread pool.",
         targetThreadPoolSize, manager.getClusterName(), manager.getInstanceName());
-    return Executors.newScheduledThreadPool(targetThreadPoolSize, new ThreadFactory() {
-      private AtomicInteger threadId = new AtomicInteger(0);
-
-      @Override
-      public Thread newThread(Runnable r) {
-        return new Thread(r, "TaskStateModelFactory-task_thread-" + threadId.getAndIncrement());
-      }
-    });
+    return Executors.newScheduledThreadPool(targetThreadPoolSize,
+            new ThreadFactoryBuilder().setNameFormat("TaskStateModelFactory-task_thread-%d").build());
   }
 }