This is an automated email from the ASF dual-hosted git repository. imaxon pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit ef5467be498a284dde179973a5d9f404cd0c95e9 Author: Michael Blow <[email protected]> AuthorDate: Thu Apr 15 18:22:57 2021 -0400 [NO ISSUE][HYR][MISC] Elimate hashtable for thread name save/restore Change-Id: Ifeea72fb253601c214a18e8f4053d7f7d2b31135 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/11084 Reviewed-by: Michael Blow <[email protected]> Reviewed-by: Ian Maxon <[email protected]> Integration-Tests: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> --- .../hyracks/util/MaintainedThreadNameExecutorService.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MaintainedThreadNameExecutorService.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MaintainedThreadNameExecutorService.java index a9ebb50..9adac04 100644 --- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MaintainedThreadNameExecutorService.java +++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MaintainedThreadNameExecutorService.java @@ -18,8 +18,6 @@ */ package org.apache.hyracks.util; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadFactory; @@ -28,7 +26,7 @@ import java.util.concurrent.TimeUnit; public class MaintainedThreadNameExecutorService extends ThreadPoolExecutor { - private final Map<Thread, String> threadNames = new ConcurrentHashMap<>(); + private static final ThreadLocal<String> savedName = new ThreadLocal<>(); private MaintainedThreadNameExecutorService(ThreadFactory threadFactory) { super(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), threadFactory); @@ -40,17 +38,13 @@ public class MaintainedThreadNameExecutorService extends ThreadPoolExecutor { @Override protected void beforeExecute(Thread t, Runnable r) { - threadNames.put(t, t.getName()); + savedName.set(t.getName()); super.beforeExecute(t, r); } @Override protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); - final Thread thread = Thread.currentThread(); - final String originalThreadName = threadNames.remove(thread); - if (originalThreadName != null) { - thread.setName(originalThreadName); - } + Thread.currentThread().setName(savedName.get()); } }
