Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit e6d72ef

Browse files
author
PonyCui
committed
fix: Use shared ThreadPoolExecutor avoid p_thread create OOM.
1 parent c6067f8 commit e6d72ef

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

library/src/main/java/com/opensource/svgaplayer/SVGADynamicEntity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SVGADynamicEntity {
4040

4141
fun setDynamicImage(url: String, forKey: String) {
4242
val handler = android.os.Handler()
43-
thread {
43+
SVGAParser.threadPoolExecutor.execute {
4444
(URL(url).openConnection() as? HttpURLConnection)?.let {
4545
try {
4646
it.connectTimeout = 20 * 1000

library/src/main/java/com/opensource/svgaplayer/SVGAParser.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SVGAParser(private val context: Context) {
4040
val cancelBlock = {
4141
cancelled = true
4242
}
43-
Thread {
43+
threadPoolExecutor.execute {
4444
try {
4545
if (HttpResponseCache.getInstalled() == null && !noCache) {
4646
Log.e("SVGAParser", "SVGAParser can not handle cache before install HttpResponseCache. see https://github.com/yyued/SVGAPlayer-Android#cache")
@@ -65,7 +65,7 @@ class SVGAParser(private val context: Context) {
6565
outputStream.write(buffer, 0, count)
6666
}
6767
if (cancelled) {
68-
return@Thread
68+
return@execute
6969
}
7070
ByteArrayInputStream(outputStream.toByteArray()).use {
7171
complete(it)
@@ -77,7 +77,7 @@ class SVGAParser(private val context: Context) {
7777
e.printStackTrace()
7878
failure(e)
7979
}
80-
}.start()
80+
}
8181
return cancelBlock
8282
}
8383

@@ -87,7 +87,7 @@ class SVGAParser(private val context: Context) {
8787

8888
companion object {
8989
private val threadPoolBlockingQueue = LinkedBlockingQueue<Runnable>()
90-
private var threadPoolExecutor = ThreadPoolExecutor(3, 10, 60000, TimeUnit.MILLISECONDS, threadPoolBlockingQueue)
90+
internal var threadPoolExecutor = ThreadPoolExecutor(3, 10, 60000, TimeUnit.MILLISECONDS, threadPoolBlockingQueue)
9191
fun setThreadPoolExecutor(executor: ThreadPoolExecutor) {
9292
threadPoolExecutor = executor
9393
}

0 commit comments

Comments
 (0)