本文实例讲述了java使用hashmap缓存保存数据的方法。分享给大家供大家参考,具体如下:
private static final HashMap<Long, XXX> sCache = new HashMap<Long, XXX>();
private static int sId = -1;
public static void initAlbumArtCache() {
try {
//。。。
if (id != sId) {
clearCache();
sId = id;
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
public static void clearCache() {
synchronized(sCache) {
sCache.clear();
}
}
public static XXX getCachedXXX(long Index, BitmapDrawable defaultBitmap) {
XXX d = null;
synchronized(sCache) {
d = sCache.get(Index);
}
if (d == null) {
//。。。
synchronized(sArtCache) {
// the cache may have changed since we checked
XXX value = sCache.get(Index);
if (value == null) {
sCache.put(Index, d);
} else {
d = value;
}
}
}
return d;
}希望本文所述对大家java程序设计有所帮助。
更多java使用hashMap缓存保存数据的方法相关文章请关注PHP中文网!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号