Merge "Removing number of threads used in background execution to prevent system thrashing" into sc-dev am: 194dcc0fd3 am: 37a9399471

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/14626498

Change-Id: I771de61dc92f071e7ddef477429fbb6d8619c52a
This commit is contained in:
Sunny Goyal
2021-05-20 04:40:30 +00:00
committed by Automerger Merge Worker
3 changed files with 8 additions and 20 deletions
+5 -16
View File
@@ -30,18 +30,15 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
public class Executors {
// 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 POOL_SIZE =
Math.max(Runtime.getRuntime().availableProcessors(), 2);
private static final int KEEP_ALIVE = 1;
/**
* An {@link ThreadPoolExecutor} to be used with async task with no limit on the queue size.
*/
public static final ThreadPoolExecutor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(
CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
TimeUnit.SECONDS, new LinkedBlockingQueue<>());
POOL_SIZE, POOL_SIZE, KEEP_ALIVE, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
/**
* Returns the executor for running tasks on the main thread.
@@ -53,7 +50,8 @@ public class Executors {
* A background executor for using time sensitive actions where user is waiting for response.
*/
public static final LooperExecutor UI_HELPER_EXECUTOR =
new LooperExecutor(createAndStartNewForegroundLooper("UiThreadHelper"));
new LooperExecutor(
createAndStartNewLooper("UiThreadHelper", Process.THREAD_PRIORITY_FOREGROUND));
/**
* Utility method to get a started handler thread statically
@@ -71,15 +69,6 @@ public class Executors {
return thread.getLooper();
}
/**
* Similar to {@link #createAndStartNewLooper(String)}, but starts the thread with
* foreground priority.
* Think before using
*/
public static Looper createAndStartNewForegroundLooper(String name) {
return createAndStartNewLooper(name, Process.THREAD_PRIORITY_FOREGROUND);
}
/**
* Executor used for running Launcher model related tasks (eg loading icons or updated db)
*/