使用Guava适配不同的callback

  1. Cache<Key,Value> cache =CacheBuilder.newBuilder()  
  2.     .maximumSize(1000)  
  3.     .build();// look Ma, no CacheLoader  
  4. ...  
  5. try{  
  6.     // If the key wasn't in the "easy to compute" group, we need to  
  7.     // do things the hard way.  
  8.     cache.get(key,newCallable<Value>(){  
  9.         @Override  
  10.         publicValue call()throwsAnyException{  
  11.             return doThingsTheHardWay(key);  
  12.         }  
  13.     });  
  14. }catch(ExecutionException e){  
  15.     thrownewOtherException(e.getCause());  
  16. }  
原文地址:https://www.cnblogs.com/panxuejun/p/7623835.html