Skip to content
Snippets Groups Projects
Commit 26628eeb authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Android (Google) Code Review
Browse files

Merge "Add thread name for PrioritizedSerialExecutor."

parents ced67885 733a9c09
No related branches found
No related tags found
No related merge requests found
...@@ -28,14 +28,14 @@ public class ExecutorUtils { ...@@ -28,14 +28,14 @@ public class ExecutorUtils {
new ConcurrentHashMap<>(); new ConcurrentHashMap<>();
/** /**
* Gets the executor for the given dictionary name. * Gets the executor for the given id.
*/ */
public static PrioritizedSerialExecutor getExecutor(final String dictName) { public static PrioritizedSerialExecutor getExecutor(final String id) {
PrioritizedSerialExecutor executor = sExecutorMap.get(dictName); PrioritizedSerialExecutor executor = sExecutorMap.get(id);
if (executor == null) { if (executor == null) {
synchronized(sExecutorMap) { synchronized(sExecutorMap) {
executor = new PrioritizedSerialExecutor(); executor = new PrioritizedSerialExecutor(id);
sExecutorMap.put(dictName, executor); sExecutorMap.put(id, executor);
} }
} }
return executor; return executor;
......
...@@ -21,6 +21,7 @@ import com.android.inputmethod.annotations.UsedForTesting; ...@@ -21,6 +21,7 @@ import com.android.inputmethod.annotations.UsedForTesting;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -40,12 +41,26 @@ public class PrioritizedSerialExecutor { ...@@ -40,12 +41,26 @@ public class PrioritizedSerialExecutor {
// The task which is running now. // The task which is running now.
private Runnable mActive; 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<>(); mTasks = new ConcurrentLinkedQueue<>();
mPrioritizedTasks = new ConcurrentLinkedQueue<>(); mPrioritizedTasks = new ConcurrentLinkedQueue<>();
mIsShutdown = false; mIsShutdown = false;
mThreadPoolExecutor = new ThreadPoolExecutor(1 /* corePoolSize */, 1 /* maximumPoolSize */, mThreadPoolExecutor = new ThreadPoolExecutor(1 /* corePoolSize */, 1 /* maximumPoolSize */,
0 /* keepAliveTime */, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1)); 0 /* keepAliveTime */, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1),
new ThreadFactoryWithId(id));
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment