Skip to content
Permalink
Browse files
[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>
  • Loading branch information
mblow committed Apr 16, 2021
1 parent c70687f commit ef5467be498a284dde179973a5d9f404cd0c95e9
Showing 1 changed file with 3 additions and 9 deletions.
@@ -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 @@ public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) {

@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());
}
}

0 comments on commit ef5467b

Please sign in to comment.