Guava库学习:学习Guava Cache(七)RemovalListener(2)
原文地址: Guava库学习:学习Guava Cache(七)RemovalListener(2)_RemovalListeners 接着上一篇 Guava库学习:学习Guava Cache(七)RemovalListener(1)_RemovalNotification ,我们继续Guava Cache RemovalListener的学习,学习Guava Cache(七)RemovalListener(2)_RemovalListeners。 RemovalListeners RemovalListeners能够帮助我们异步的处理,缓存条目移除后的通知,为了让我们的Listener可以在条目被移除时异步的处理通知,我们可以像下面这样调用RemovalListeners. asynchronous方法: private ExecutorService executor; private ListeningExecutorService executorService; @Before public void setUp() { executor = Executors.newCachedThreadPool(); executorService = MoreExecutors.listeningDecorator(executor); } @Test public void