@Test public void testString() { final String key = "baidu_beidou"; Object result = cache.get(key, new Callable<Object>() { @Override public Object call() throws Exception { return StringUtil.toCamelCase(key); } }); assertEquals("baiduBeidou", result); }
public V get(K key, Callable<V> callable) { Future<V> future = concurrentMap.get(key); if (future == null) { FutureTask<V> futureTask = new FutureTask<V>(callable); future = concurrentMap.putIfAbsent(key, futureTask); if (future == null) { future = futureTask; futureTask.run(); } } try { return future.get(); } catch (Exception e) { concurrentMap.remove(key); return null; } }
ConcurrentCache implements Computable<K, V> { public V get(K key, Callable<V> callable) { Future<V> future = concurrentMap.get(key); if (future == null) { FutureTask<V> futureTask = new FutureTask<V>(callable); future = concurrentMap.putIfAbsent(key, futureTask); if (future == null) { future = futureTask; futureTask.run(); } } try { return future.get(); } catch (Exception e) { concurrentMap.remove(key); return null; } } }
ConcurrentCache implements Computable<K, V> { public V get(K key, Callable<V> callable) { Future<V> future = concurrentMap.get(key); if (future == null) { FutureTask<V> futureTask = new FutureTask<V>(callable); future = concurrentMap.putIfAbsent(key, futureTask); if (future == null) { future = futureTask; futureTask.run(); } } try { return future.get(); } catch (Exception e) { concurrentMap.remove(key); return null; } } ConcurrentCache(); }
ConcurrentCache implements Computable<K, V> { public V get(K key, Callable<V> callable) { Future<V> future = concurrentMap.get(key); if (future == null) { FutureTask<V> futureTask = new FutureTask<V>(callable); future = concurrentMap.putIfAbsent(key, futureTask); if (future == null) { future = futureTask; futureTask.run(); } } try { return future.get(); } catch (Exception e) { concurrentMap.remove(key); return null; } } ConcurrentCache(); static Computable<K, V> createComputable(); V get(K key, Callable<V> callable); }
ConcurrentCache implements Computable<K, V> { public V get(K key, Callable<V> callable) { Future<V> future = concurrentMap.get(key); if (future == null) { FutureTask<V> futureTask = new FutureTask<V>(callable); future = concurrentMap.putIfAbsent(key, futureTask); if (future == null) { future = futureTask; futureTask.run(); } } try { return future.get(); } catch (Exception e) { concurrentMap.remove(key); return null; } } ConcurrentCache(); static Computable<K, V> createComputable(); V get(K key, Callable<V> callable);  }