diff options
author | zachh <zachh@google.com> | 2017-07-13 16:22:50 -0700 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2017-07-24 18:48:14 +0000 |
commit | 4ad32fe2dc7b27adc7a811223c2dc2bdf9e50afb (patch) | |
tree | cfca583eb15d85aaf7ccf8c120b8d6fdef09b4e0 /java/com/android/dialer/common/concurrent | |
parent | 687f1931532d66b51790998b318abca6a0d3f928 (diff) |
Use a shared thread pool for spam transport.
Before, we were creating a custom thread pool for spam transport, which isn't necessary. Instead, we can just use an application wide thread pool.
Also fixed some instances where we were not clearing the thread stats tag after opening the socket.
Test: manually launched app with data cleared and observed no crash
PiperOrigin-RevId: 161882076
Change-Id: I39bdd31cf5fa8a974d7535e861ec0716c85986f3
Diffstat (limited to 'java/com/android/dialer/common/concurrent')
-rw-r--r-- | java/com/android/dialer/common/concurrent/DefaultDialerExecutorFactory.java | 12 | ||||
-rw-r--r-- | java/com/android/dialer/common/concurrent/DialerExecutors.java | 27 |
2 files changed, 28 insertions, 11 deletions
diff --git a/java/com/android/dialer/common/concurrent/DefaultDialerExecutorFactory.java b/java/com/android/dialer/common/concurrent/DefaultDialerExecutorFactory.java index 82e517d9a..a87bbceb4 100644 --- a/java/com/android/dialer/common/concurrent/DefaultDialerExecutorFactory.java +++ b/java/com/android/dialer/common/concurrent/DefaultDialerExecutorFactory.java @@ -166,17 +166,7 @@ public class DefaultDialerExecutorFactory implements DialerExecutorFactory { }); private static final Executor defaultParallelExecutor = - Executors.newFixedThreadPool( - 5, - new ThreadFactory() { - @Override - public Thread newThread(Runnable runnable) { - LogUtil.i("NonUiTaskBuilder.newThread", "creating parallel thread"); - Thread thread = new Thread(runnable, "NonUiTaskBuilder-Parallel"); - thread.setPriority(4); // Corresponds to Process.THREAD_PRIORITY_BACKGROUND - return thread; - } - }); + DialerExecutors.getLowPriorityThreadPool(); NonUiTaskBuilder(Worker<InputT, OutputT> worker) { this(worker, defaultSerialExecutorService, defaultParallelExecutor); diff --git a/java/com/android/dialer/common/concurrent/DialerExecutors.java b/java/com/android/dialer/common/concurrent/DialerExecutors.java index 148d8660c..81b3c5cb3 100644 --- a/java/com/android/dialer/common/concurrent/DialerExecutors.java +++ b/java/com/android/dialer/common/concurrent/DialerExecutors.java @@ -19,7 +19,11 @@ package com.android.dialer.common.concurrent; import android.app.FragmentManager; import android.support.annotation.NonNull; import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutor.Worker; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; /** * Factory methods for creating {@link DialerExecutor} objects for doing background work. @@ -131,4 +135,27 @@ public final class DialerExecutors { @NonNull Worker<InputT, OutputT> worker) { return new DefaultDialerExecutorFactory().createNonUiTaskBuilder(Assert.isNotNull(worker)); } + + private static final Executor lowPriorityThreadPool = + Executors.newFixedThreadPool( + 5, + new ThreadFactory() { + @Override + public Thread newThread(Runnable runnable) { + LogUtil.i("DialerExecutors.newThread", "creating low priority thread"); + Thread thread = new Thread(runnable, "DialerExecutors-LowPriority"); + thread.setPriority(4); // Corresponds to Process.THREAD_PRIORITY_BACKGROUND + return thread; + } + }); + + /** + * An application-wide thread pool used for low priority (non-UI) tasks. + * + * <p>This exists to prevent each individual dialer component from having to create its own + * threads/pools, which would result in the application having more threads than really necessary. + */ + public static Executor getLowPriorityThreadPool() { + return lowPriorityThreadPool; + } } |