Make more threads in the executor for background tasks
Let injected preferences load data simultaneously without being blocked by other ones. Bug: 141694556 Test: make RunSettingsLibRoboTests -j Change-Id: If10ef8c367492dcbd8aba66c1b01036fc79a8093
This commit is contained in:
@@ -26,7 +26,7 @@ public class ThreadUtils {
|
||||
|
||||
private static volatile Thread sMainThread;
|
||||
private static volatile Handler sMainThreadHandler;
|
||||
private static volatile ExecutorService sSingleThreadExecutor;
|
||||
private static volatile ExecutorService sThreadExecutor;
|
||||
|
||||
/**
|
||||
* Returns true if the current thread is the UI thread.
|
||||
@@ -64,10 +64,11 @@ public class ThreadUtils {
|
||||
* @Return A future of the task that can be monitored for updates or cancelled.
|
||||
*/
|
||||
public static Future postOnBackgroundThread(Runnable runnable) {
|
||||
if (sSingleThreadExecutor == null) {
|
||||
sSingleThreadExecutor = Executors.newSingleThreadExecutor();
|
||||
if (sThreadExecutor == null) {
|
||||
sThreadExecutor = Executors.newFixedThreadPool(
|
||||
Runtime.getRuntime().availableProcessors());
|
||||
}
|
||||
return sSingleThreadExecutor.submit(runnable);
|
||||
return sThreadExecutor.submit(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ThreadUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostOnMainThread_shouldRunOnMainTread() {
|
||||
public void testPostOnMainThread_shouldRunOnMainThread() {
|
||||
TestRunnable cr = new TestRunnable();
|
||||
ShadowLooper.pauseMainLooper();
|
||||
ThreadUtils.postOnMainThread(cr);
|
||||
|
||||
Reference in New Issue
Block a user