-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
修复多线程导致的ConcurrentModificationException
- Loading branch information
1 parent
1f00aa8
commit 7564c05
Showing
4 changed files
with
33 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,6 @@ | |
|
||
package com.lt.load_the_image.cache | ||
|
||
import java.util.Collections | ||
|
||
/** | ||
* creator: lt 2022/4/8 [email protected] | ||
* effect : Memory cache configuration of network image, cache use LRU | ||
|
@@ -27,13 +25,12 @@ open class ImageLruMemoryCache( | |
private val maxMemorySize: Long = getMemoryWithOnePercent() | ||
) : ImageCache { | ||
//image lru cache | ||
private val cacheMap = Collections.synchronizedMap( | ||
LinkedHashMap<String, ByteArray>(35, 1f, true) | ||
) | ||
private val cacheMap = LinkedHashMap<String, ByteArray>(35, 1f, true) | ||
|
||
//image cache byte size sum | ||
private var cacheSize: Long = 0 | ||
|
||
@Synchronized | ||
override fun saveCache(url: String, t: ByteArray) { | ||
if (t.size > maxMemorySize) | ||
return | ||
|
@@ -45,6 +42,7 @@ open class ImageLruMemoryCache( | |
} | ||
} | ||
|
||
@Synchronized | ||
override fun getCache(url: String): ByteArray? { | ||
return cacheMap[url] | ||
} | ||
|