构建高效且可伸缩的结果缓存
public interface Computable<A, V> {
V compute(A arg) throws InterruptedException;
}
public class ExpensiveFunction implements Computable<String, BigInteger> {
@Override
public BigInteger compute(String arg) throws InterruptedException {
// 经过长时间的运算后
return new BigInteger(arg);
}
}使用HashMap和同步进行实现

使用ConcurrentHashMap进行改进

添加FutureTask进行改进

使用putIfAbsent方法
最后更新于