From 1e697fa734f2ecdcf2ab802fc52c07cb833a9667 Mon Sep 17 00:00:00 2001 From: NineWorlds <1365887550@qq.com> Date: Sat, 31 Jul 2021 14:42:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=87=E5=A4=9A=E7=9A=84=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E6=97=A0=E7=94=A8=EF=BC=8C8=E7=BA=BF=E7=A8=8B=E5=B7=B2?= =?UTF-8?q?=E8=B6=B3=E5=A4=9F=EF=BC=9B=E7=BD=91=E7=BB=9C=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E4=BA=A4=E7=94=B1=E5=8D=8F=E7=A8=8B=E8=B0=83=E5=BA=A6=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E5=BD=B1=E5=93=8D=E5=B9=B6=E5=8F=91=E9=87=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/model/webBook/SearchBookModel.kt | 2 +- app/src/main/java/io/legado/app/service/CacheBookService.kt | 3 ++- app/src/main/java/io/legado/app/service/CheckSourceService.kt | 2 +- .../io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt | 2 +- .../legado/app/ui/book/changesource/ChangeSourceViewModel.kt | 3 ++- app/src/main/java/io/legado/app/ui/main/MainViewModel.kt | 4 ++-- 6 files changed, 9 insertions(+), 7 deletions(-) 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() {