diff --git a/app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt b/app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt index e07c16116..3397e6198 100644 --- a/app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt +++ b/app/src/main/java/io/legado/app/model/webBook/SearchBookModel.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) { diff --git a/app/src/main/java/io/legado/app/service/CacheBookService.kt b/app/src/main/java/io/legado/app/service/CacheBookService.kt index 9ed25441b..4f95185f0 100644 --- a/app/src/main/java/io/legado/app/service/CacheBookService.kt +++ b/app/src/main/java/io/legado/app/service/CacheBookService.kt @@ -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() } diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index f3cf07cb5..e9a7ff6fe 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -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() private val checkedIds = ArrayList() diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt index cdd67fb02..406ba4071 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt @@ -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 } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index 7fa050b36..74b9aa099 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -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 } diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 272b1ffc1..201ceba13 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -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() private val bookMap = ConcurrentHashMap() @@ -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() {