[Android] Ensure we correctly set ThreadPoolExecutor up

Geoffrey Métais git at videolan.org
Mon Mar 6 15:06:06 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Mar  6 15:00:08 2017 +0100| [303753a9756baa5a4d40ab5bb112ba70eb049ab1] | committer: Geoffrey Métais

Ensure we correctly set ThreadPoolExecutor up

Avoid setting a core threads number greater than max

> https://code.videolan.org/videolan/vlc-android/commit/303753a9756baa5a4d40ab5bb112ba70eb049ab1
---

 vlc-android/src/org/videolan/vlc/VLCApplication.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index 3b6a577..016ee6d 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -67,7 +67,8 @@ public class VLCApplication extends Application {
     private static SimpleArrayMap<String, Object> sDataMap = new SimpleArrayMap<>();
 
     /* Up to 2 threads maximum, inactive threads are killed after 2 seconds */
-    private ThreadPoolExecutor mThreadPool = new ThreadPoolExecutor(2, AndroidUtil.isJellyBeanMR1OrLater() ? Runtime.getRuntime().availableProcessors() : 2, 2, TimeUnit.SECONDS,
+    int maxThreads = Math.max(AndroidUtil.isJellyBeanMR1OrLater() ? Runtime.getRuntime().availableProcessors() : 2, 1);
+    private ThreadPoolExecutor mThreadPool = new ThreadPoolExecutor(Math.min(2, maxThreads), maxThreads, 2, TimeUnit.SECONDS,
             new LinkedBlockingQueue<Runnable>(), THREAD_FACTORY);
     public static final ThreadFactory THREAD_FACTORY = new ThreadFactory() {
         @Override



More information about the Android mailing list