[Android] Specific threadpool to queue ML processing
Geoffrey Métais
git at videolan.org
Tue Apr 11 15:09:00 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Apr 11 15:07:59 2017 +0200| [9372426fc3f8c894488c5c541ceaab164f7d905e] | committer: Geoffrey Métais
Specific threadpool to queue ML processing
> https://code.videolan.org/videolan/vlc-android/commit/9372426fc3f8c894488c5c541ceaab164f7d905e
---
.../src/org/videolan/vlc/MediaParsingService.java | 36 ++++++++++++++++------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.java b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
index 61608e6..73a6ede 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.java
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
@@ -28,6 +28,9 @@ import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.Util;
import java.io.File;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
public class MediaParsingService extends Service implements DevicesDiscoveryCb {
public final static String TAG = "VLC/MediaParsingService";
@@ -52,6 +55,9 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
private String mCurrentDiscovery = null;
private long mLastNotificationTime = 0L;
+ private final ThreadPoolExecutor mThreadPool = new ThreadPoolExecutor(1, 1, 30, TimeUnit.SECONDS,
+ new LinkedBlockingQueue<Runnable>(), VLCApplication.THREAD_FACTORY);
+
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -119,19 +125,29 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
return START_NOT_STICKY;
}
- private void discoverStorage(String path, String uuid) {
- if (!TextUtils.isEmpty(uuid))
- mMedialibrary.addDevice(uuid, path, true);
- for (String folder : Medialibrary.getBlackList())
- mMedialibrary.banFolder(path + folder);
- mMedialibrary.discover(path);
+ private void discoverStorage(final String path, final String uuid) {
+ mThreadPool.execute(new Runnable() {
+ @Override
+ public void run() {
+ if (!TextUtils.isEmpty(uuid))
+ mMedialibrary.addDevice(uuid, path, true);
+ for (String folder : Medialibrary.getBlackList())
+ mMedialibrary.banFolder(path + folder);
+ mMedialibrary.discover(path);
+ }
+ });
}
- private void discover(String path) {
+ private void discover(final String path) {
if (TextUtils.isEmpty(path))
return;
- addDeviceIfNeeded(path);
- mMedialibrary.discover(path);
+ mThreadPool.execute(new Runnable() {
+ @Override
+ public void run() {
+ addDeviceIfNeeded(path);
+ mMedialibrary.discover(path);
+ }
+ });
}
private void addDeviceIfNeeded(String path) {
@@ -157,7 +173,7 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
if (mMedialibrary.isInitiated())
mMedialibrary.resumeBackgroundOperations();
else
- VLCApplication.runBackground(new Runnable() {
+ mThreadPool.execute(new Runnable() {
@Override
public void run() {
mMedialibrary.setup();
More information about the Android
mailing list