[Android] Add a background queue and enlarge threadpool
Geoffrey Métais
git at videolan.org
Thu Jan 12 17:15:43 CET 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jan 12 17:01:13 2017 +0100| [f8974f98ff23432b2285eadf967185b5b29804ee] | committer: Geoffrey Métais
Add a background queue and enlarge threadpool
> https://code.videolan.org/videolan/vlc-android/commit/f8974f98ff23432b2285eadf967185b5b29804ee
---
vlc-android/src/org/videolan/vlc/VLCApplication.java | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index 0cf527e..d921fae 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -36,6 +36,7 @@ import android.text.TextUtils;
import android.util.Log;
import org.videolan.libvlc.Dialog;
+import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.vlc.gui.DialogActivity;
import org.videolan.vlc.gui.dialogs.VlcProgressDialog;
@@ -69,7 +70,9 @@ 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(0, 2, 2, TimeUnit.SECONDS,
+ private ThreadPoolExecutor mThreadPool = new ThreadPoolExecutor(0, AndroidUtil.isJellyBeanMR1OrLater() ? Runtime.getRuntime().availableProcessors() : 2, 2, TimeUnit.SECONDS,
+ new LinkedBlockingQueue<Runnable>(), THREAD_FACTORY);
+ private ThreadPoolExecutor mThreadPoolSingle = new ThreadPoolExecutor(0, 1, 2, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(), THREAD_FACTORY);
public static final ThreadFactory THREAD_FACTORY = new ThreadFactory() {
@Override
@@ -182,6 +185,12 @@ public class VLCApplication extends Application {
instance.mThreadPool.execute(runnable);
}
+ public static void queueBackground(Runnable runnable, boolean clear) {
+ if (clear)
+ instance.mThreadPoolSingle.getQueue().clear();
+ instance.mThreadPoolSingle.execute(runnable);
+ }
+
public static void runOnMainThread(Runnable runnable) {
instance.mHandler.post(runnable);
}
More information about the Android
mailing list