[Android] Use a threadpool for I/O operations

Geoffrey Métais git at videolan.org
Thu Jul 12 15:38:48 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jul 12 15:31:58 2018 +0200| [da4e3330d5981687c1f2a21eaa5397c06eba646e] | committer: Geoffrey Métais

Use a threadpool for I/O operations

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

 vlc-android/src/org/videolan/vlc/util/Workers.kt | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/Workers.kt b/vlc-android/src/org/videolan/vlc/util/Workers.kt
index 12f559d8e..5493ea5ce 100644
--- a/vlc-android/src/org/videolan/vlc/util/Workers.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Workers.kt
@@ -1,10 +1,21 @@
 package org.videolan.vlc.util
 
 import android.os.Looper
+import android.os.Process
 import kotlinx.coroutines.experimental.*
 import kotlinx.coroutines.experimental.android.UI
+import kotlinx.coroutines.experimental.timeunit.TimeUnit
+import java.util.concurrent.SynchronousQueue
+import java.util.concurrent.ThreadFactory
+import java.util.concurrent.ThreadPoolExecutor
 
-val VLCIO = newSingleThreadContext("vlc-io")
+
+//val VLCIO = newSingleThreadContext("vlc-io")
+private val THREAD_FACTORY: ThreadFactory = ThreadFactory { runnable ->
+    Thread(runnable).apply { priority = Thread.NORM_PRIORITY + Process.THREAD_PRIORITY_LESS_FAVORABLE }
+}
+
+val VLCIO = ThreadPoolExecutor(1, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, SynchronousQueue<Runnable>(), THREAD_FACTORY).asCoroutineDispatcher()
 private val mainThread = Looper.getMainLooper().thread!!
 private val uiDispatch inline get() = mainThread != Thread.currentThread()
 



More information about the Android mailing list