public interface CachedLoadService {
Map<String,Object> loadHomeData();
}
public class CachedUtils {
private static Date lastSearchTime=null;
private static Map mapMediaList=null;
static Object lock = new Object();
public static Map getMediaList() {
synchronized (lock) {
CachedLoadService cachedLoadService=(CachedLoadService) SpringContextUtil.getBean("cachedLoadService"); //或者其它业务类
try {
if(lastSearchTime==null) {
mapMediaList=cachedLoadService.loadHomeData();
lastSearchTime=new Date();
} else {
if(mapMediaList==null) {
mapMediaList=cachedLoadService.loadHomeData();
lastSearchTime=new Date();
} else {
mapMediaList=cachedLoadService.loadHomeData();
lastSearchTime=new Date();
}
}
return mapMediaList;
} catch (Exception e) {
return mapMediaList;
}
}
}
}
cachedLoadService.loadHomeData() 就是一个 final static Map<String,Object> ,还有必要去特意弄一个接口吗?这种做法的作用是什么?
烙印99
温温酱
相关分类