You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by im...@apache.org on 2021/05/26 23:43:11 UTC
[asterixdb] 05/38: [NO ISSUE][HYR][MISC] Elimate hashtable for
thread name save/restore
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 <mb...@apache.org>
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 <mb...@apache.org>
Reviewed-by: Ian Maxon <im...@uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
---
.../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());
}
}