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

Commit

Permalink
fix: Use shared ThreadPoolExecutor avoid p_thread create OOM.
Browse files Browse the repository at this point in the history
  • Loading branch information
PonyCui committed Jul 24, 2019
1 parent c6067f8 commit e6d72ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SVGADynamicEntity {

fun setDynamicImage(url: String, forKey: String) {
val handler = android.os.Handler()
thread {
SVGAParser.threadPoolExecutor.execute {
(URL(url).openConnection() as? HttpURLConnection)?.let {
try {
it.connectTimeout = 20 * 1000
Expand Down
8 changes: 4 additions & 4 deletions library/src/main/java/com/opensource/svgaplayer/SVGAParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SVGAParser(private val context: Context) {
val cancelBlock = {
cancelled = true
}
Thread {
threadPoolExecutor.execute {
try {
if (HttpResponseCache.getInstalled() == null && !noCache) {
Log.e("SVGAParser", "SVGAParser can not handle cache before install HttpResponseCache. see https://github.com/yyued/SVGAPlayer-Android#cache")
Expand All @@ -65,7 +65,7 @@ class SVGAParser(private val context: Context) {
outputStream.write(buffer, 0, count)
}
if (cancelled) {
return@Thread
return@execute
}
ByteArrayInputStream(outputStream.toByteArray()).use {
complete(it)
Expand All @@ -77,7 +77,7 @@ class SVGAParser(private val context: Context) {
e.printStackTrace()
failure(e)
}
}.start()
}
return cancelBlock
}

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

companion object {
private val threadPoolBlockingQueue = LinkedBlockingQueue<Runnable>()
private var threadPoolExecutor = ThreadPoolExecutor(3, 10, 60000, TimeUnit.MILLISECONDS, threadPoolBlockingQueue)
internal var threadPoolExecutor = ThreadPoolExecutor(3, 10, 60000, TimeUnit.MILLISECONDS, threadPoolBlockingQueue)
fun setThreadPoolExecutor(executor: ThreadPoolExecutor) {
threadPoolExecutor = executor
}
Expand Down

0 comments on commit e6d72ef

Please sign in to comment.