Tag: concurrent

  • 并发,缓存与guava

    作为一个已经用了很长时间缓存的javaer,老实说到今天为止才真正知道缓存该怎么用。为什么这么说呢?考虑如下代码: public Object compute(Object key) { Object value = null; if ( (value = cache.get(key)) == null ) { value = compteValue(key); } cache.put(key, value); } 是不是很熟悉?典型的缓存客户端代码,但是这段代码是有问题的。问题不在cache,而在于这段代码本身。考虑如下的场景: