diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index 8f43248db..71cd0311d 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -23,6 +23,8 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.isActive import org.jetbrains.anko.toast +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.CopyOnWriteArraySet import java.util.concurrent.Executors class DownloadService : BaseService() { @@ -32,12 +34,12 @@ class DownloadService : BaseService() { private var tasks = CompositeCoroutine() private val handler = Handler() private var runnable: Runnable = Runnable { upDownload() } - private val bookMap = hashMapOf() - private val webBookMap = hashMapOf() - private val downloadMap = hashMapOf>() - private val downloadCount = hashMapOf() - private val finalMap = hashMapOf>() - private val downloadingList = arrayListOf() + private val bookMap = ConcurrentHashMap() + private val webBookMap = ConcurrentHashMap() + private val downloadMap = ConcurrentHashMap>() + private val downloadCount = ConcurrentHashMap() + private val finalMap = ConcurrentHashMap>() + private val downloadingList = CopyOnWriteArraySet() @Volatile private var downloadingCount = 0 @@ -131,7 +133,7 @@ class DownloadService : BaseService() { execute { App.db.bookChapterDao().getChapterList(bookUrl, start, end).let { if (it.isNotEmpty()) { - val chapters = linkedSetOf() + val chapters = CopyOnWriteArraySet() chapters.addAll(it) downloadMap[bookUrl] = chapters } @@ -202,7 +204,7 @@ class DownloadService : BaseService() { } val chapterMap = finalMap[book.bookUrl] - ?: linkedSetOf().apply { + ?: CopyOnWriteArraySet().apply { finalMap[book.bookUrl] = this } chapterMap.add(bookChapter)