java使用hashMap缓存保存数据的方法
java使用hashMap缓存保存数据的方法
发布时间:2016-12-28 来源:查字典编辑
摘要:本文实例讲述了java使用hashMap缓存保存数据的方法。分享给大家供大家参考,具体如下:privatestaticfinalHashMa...

本文实例讲述了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学习
热门Java学习
编程开发子分类