[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 <mblow@apache.org>
Reviewed-by: Ian Maxon <imaxon@uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
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 @@
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 @@
@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());
}
}