Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6417cbb2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make more threads in the executor for background tasks"

parents 4e756b4f 92de722b
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -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);
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -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);