Using custom threadpool executor instead of the one defined in AsyncTask

Change-Id: I8fe95d932c5de14c74f0576bfc3d1f641d12b448
This commit is contained in:
Sunny Goyal
2015-09-23 15:38:09 -07:00
parent ce0a89461a
commit 8ac727b2c6
6 changed files with 21 additions and 19 deletions

View File

@@ -43,25 +43,12 @@ import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class WidgetPreviewLoader {
private static final String TAG = "WidgetPreviewLoader";
private static final boolean DEBUG = false;
// These values are same as that in {@link AsyncTask}.
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
private static final int KEEP_ALIVE = 1;
private static final Executor PREVIEW_LOAD_EXECUTOR = new ThreadPoolExecutor(
CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
private static final float WIDGET_PREVIEW_ICON_PADDING_PERCENTAGE = 0.25f;
private final HashMap<String, long[]> mPackageVersions = new HashMap<>();
@@ -109,7 +96,7 @@ public class WidgetPreviewLoader {
WidgetCacheKey key = getObjectKey(o, size);
PreviewLoadTask task = new PreviewLoadTask(key, o, previewWidth, previewHeight, caller);
task.executeOnExecutor(PREVIEW_LOAD_EXECUTOR);
task.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
return new PreviewLoadRequest(task);
}