缓存设计
来源:互联网 发布:数据库查询去掉重复 编辑:程序博客网 时间:2024/06/10 07:49
V compute(A arg) throws InterruptedException;
}
public class ExpensiveFunctuion implements Computable<String, Integer> {
public Integer compute(String arg) throws InterruptedException {
//do..............
return new Integer(arg);
}
}
public class Memoizer3<A, V> implements Computable<A, V> {
private final ConcurrentMap<A, FutureTask<V>> cache = new ConcurrentHashMap<A, FutureTask<V>>();
private final Computable<A, V> c;
// performance is good
public V compute(final A arg) throws InterruptedException {
FutureTask<V> f = cache.get(arg);
if (f == null) {
Callable eval = new Callable() {
public Object call() throws Exception {
return c.compute(arg);
}
};
FutureTask<V> ft = new FutureTask<V>(eval);
f = cache.putIfAbsent(arg, ft);
if(f==null){
f=ft;
ft.run();
}
ft.run();
}
try {
return f.get();
} catch (Exception e) {
cache.remove(arg,f);
}
return null;
}
public Memoizer3(Computable<A, V> c) {
this.c = c;
}
}
- 缓存设计
- 缓存设计
- 缓存设计
- 缓存设计
- 设计缓存
- android缓存设计-文件缓存
- 缓存的设计
- 简单缓存设计
- javascript设计缓存系统
- 缓存类设计
- 缓存设计介绍
- 缓存设计介绍
- LRU缓存设计
- 缓存子系统如何设计
- android缓存设计
- LRU缓存设计
- 设计LRU缓存
- android缓存设计
- MyEclipse10破解激活方法 亲测
- java学习路线
- zoj3802 状压dp
- 用js把数据从一个页面传到另一个页面
- CSDN中国软件开发联盟(Chinese software develop net)开通博客 .
- 缓存设计
- node.js 单线程异步理解
- yii图片上传教程
- web前端开发工具
- linux mysql自动备份脚本改写实现
- session同步
- lucence helloword
- POJ-3225 Help with Intervals
- ActiveMQ