过多的线程无用,8线程已足够;网络并发交由协程调度,不影响并发量。

pull/1194/head
NineWorlds 3 years ago
parent 781c9cea12
commit 1e697fa734
  1. 2
      app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt
  2. 3
      app/src/main/java/io/legado/app/service/CacheBookService.kt
  3. 2
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt
  5. 3
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt
  6. 4
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt

@ -27,7 +27,7 @@ class SearchBookModel(private val scope: CoroutineScope, private val callBack: C
private var searchIndex = -1
private fun initSearchPool() {
searchPool = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher()
searchPool = Executors.newFixedThreadPool(min(threadCount,8)).asCoroutineDispatcher()
}
fun search(searchId: Long, key: String) {

@ -27,11 +27,12 @@ import splitties.init.appCtx
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArraySet
import java.util.concurrent.Executors
import kotlin.math.min
class CacheBookService : BaseService() {
private val threadCount = AppConfig.threadCount
private var searchPool =
Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher()
Executors.newFixedThreadPool(min(threadCount,8)).asCoroutineDispatcher()
private var tasks = CompositeCoroutine()
private val handler = Handler(Looper.getMainLooper())
private var runnable: Runnable = Runnable { upDownload() }

@ -24,7 +24,7 @@ import kotlin.math.min
class CheckSourceService : BaseService() {
private var threadCount = AppConfig.threadCount
private var searchCoroutine = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher()
private var searchCoroutine = Executors.newFixedThreadPool(min(threadCount,8)).asCoroutineDispatcher()
private var tasks = CompositeCoroutine()
private val allIds = ArrayList<String>()
private val checkedIds = ArrayList<String>()

@ -50,7 +50,7 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
}
private fun initSearchPool() {
searchPool = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher()
searchPool = Executors.newFixedThreadPool(min(threadCount,8)).asCoroutineDispatcher()
searchIndex = -1
}

@ -24,6 +24,7 @@ import kotlinx.coroutines.asCoroutineDispatcher
import splitties.init.appCtx
import java.util.concurrent.CopyOnWriteArraySet
import java.util.concurrent.Executors
import kotlin.math.min
class ChangeSourceViewModel(application: Application) : BaseViewModel(application) {
private val threadCount = AppConfig.threadCount
@ -56,7 +57,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
}
private fun initSearchPool() {
searchPool = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher()
searchPool = Executors.newFixedThreadPool(min(threadCount,8)).asCoroutineDispatcher()
searchIndex = -1
}

@ -23,7 +23,7 @@ import kotlin.math.min
class MainViewModel(application: Application) : BaseViewModel(application) {
private var threadCount = AppConfig.threadCount
private var upTocPool = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher()
private var upTocPool = Executors.newFixedThreadPool(min(threadCount,8)).asCoroutineDispatcher()
val updateList = CopyOnWriteArraySet<String>()
private val bookMap = ConcurrentHashMap<String, Book>()
@ -38,7 +38,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
fun upPool() {
threadCount = AppConfig.threadCount
upTocPool.close()
upTocPool = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher()
upTocPool = Executors.newFixedThreadPool(min(threadCount,8)).asCoroutineDispatcher()
}
fun upAllBookToc() {

Loading…
Cancel
Save