From 733a9c09a90c537e0ec00d3d38a1e124662750bb Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Tue, 27 May 2014 16:06:08 +0900 Subject: [PATCH] Add thread name for PrioritizedSerialExecutor. Bug: 15270123 Change-Id: I655ba97f0543476980d0e8461bc1c8a56c9f954b --- .../latin/utils/ExecutorUtils.java | 10 +++++----- .../utils/PrioritizedSerialExecutor.java | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/utils/ExecutorUtils.java b/java/src/com/android/inputmethod/latin/utils/ExecutorUtils.java index 7b678e175..c08697c4b 100644 --- a/java/src/com/android/inputmethod/latin/utils/ExecutorUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/ExecutorUtils.java @@ -28,14 +28,14 @@ public class ExecutorUtils { new ConcurrentHashMap<>(); /** - * Gets the executor for the given dictionary name. + * Gets the executor for the given id. */ - public static PrioritizedSerialExecutor getExecutor(final String dictName) { - PrioritizedSerialExecutor executor = sExecutorMap.get(dictName); + public static PrioritizedSerialExecutor getExecutor(final String id) { + PrioritizedSerialExecutor executor = sExecutorMap.get(id); if (executor == null) { synchronized(sExecutorMap) { - executor = new PrioritizedSerialExecutor(); - sExecutorMap.put(dictName, executor); + executor = new PrioritizedSerialExecutor(id); + sExecutorMap.put(id, executor); } } return executor; diff --git a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java index 148f3bce6..21949ffbd 100644 --- a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java +++ b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java @@ -21,6 +21,7 @@ import com.android.inputmethod.annotations.UsedForTesting; import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -40,12 +41,26 @@ public class PrioritizedSerialExecutor { // The task which is running now. private Runnable mActive; - public PrioritizedSerialExecutor() { + private static class ThreadFactoryWithId implements ThreadFactory { + private final String mId; + + public ThreadFactoryWithId(final String id) { + mId = id; + } + + @Override + public Thread newThread(final Runnable r) { + return new Thread(r, TAG + " - " + mId); + } + } + + public PrioritizedSerialExecutor(final String id) { mTasks = new ConcurrentLinkedQueue<>(); mPrioritizedTasks = new ConcurrentLinkedQueue<>(); mIsShutdown = false; mThreadPoolExecutor = new ThreadPoolExecutor(1 /* corePoolSize */, 1 /* maximumPoolSize */, - 0 /* keepAliveTime */, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1)); + 0 /* keepAliveTime */, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), + new ThreadFactoryWithId(id)); } /**