public class MemoryCard {
private static Map<String, AccountCache> caches = new HashMap<String, AccountCache>(); /**
* 存入缓存
* @param key
* @param cache
*/
public void putCache(String key, AccountCache accountCache) {
caches.put(key, accountCache);
}
/**
* 获取对应缓存
* @param key
* @return
*/
public AccountCache getCacheByKey(String key) {
if (caches.containsKey(key)) {
return caches.get(key);
}
return null;
}
}
这是写的缓存类,定时器没过30秒去数据库查询数据,再调用putCache方法,但是测试的时候发现比如有两个map值,
key1的value是value1,key2的value是value2,但是后面getCacheByKey取值的时候,取到key1的value是value1,key2的value是value1,死活找不出原因了
private static Map<String, AccountCache> caches = new HashMap<String, AccountCache>(); /**
* 存入缓存
* @param key
* @param cache
*/
public void putCache(String key, AccountCache accountCache) {
caches.put(key, accountCache);
}
/**
* 获取对应缓存
* @param key
* @return
*/
public AccountCache getCacheByKey(String key) {
if (caches.containsKey(key)) {
return caches.get(key);
}
return null;
}
}
这是写的缓存类,定时器没过30秒去数据库查询数据,再调用putCache方法,但是测试的时候发现比如有两个map值,
key1的value是value1,key2的value是value2,但是后面getCacheByKey取值的时候,取到key1的value是value1,key2的value是value1,死活找不出原因了
解决方案 »
- java 数据库连接(oracle)
- eclipse怎么无法安装google app engine插件
- 免费的应用中间件之间的比较?
- 图片等比缩放后为什么时大时小?
- 怎么将页面的数据存到TXT文件中
- 用尽的Resultset问题,奇怪啊!!
- jsp中javascript问题,急!
- 交流一下java的学习经验吧!
- jsp输出图片的问题!
- 寻找一个oracle驱动!!!!!!!!!!!!急死我了!!!!!!!!!!!!
- 一个hibernate的session配置问题
- 求助,java.lang.IllegalStateException: Cannot call sendError() after the resp,找不到原因
类似于AccountCache ac = getCacheByKey("key1");
putCache("key1", ac);
ac = getCacheByKey("key1");
putCache("key2", ac);
AccountCache ac = getCacheByKey("key1");
putCache("key1", ac);
ac = getCacheByKey("key2");
putCache("key2", ac);
if (key.equals("key1")) {
String value1 = caches.get(key1).toString();}
if (key.equals("key2")) {
String value2 = caches.get(key2).toString();}
}