2011-09-22 23 views
2

我已經在我的Classpath中使用Guava,並且想要使用ListenableFuture s,但是目前我不知道如何提交ListenableFuture s,或者目前只能在調用線程中使用它們而沒有執行程序嗎?我讀過r10中有一個裝飾器沒有出來?ListenableFutureTask/ExecutorService

我發現Futures.makeListenable(Future<V> future),但我不確定這是目前如何使用ListenableFuture s的唯一方法。

親切的問候,
約翰內斯

回答

3

我們提高了ListenableFuture的Javadoc爲即將到來的R10,包括增加有關如何獲取類的實例的信息。你可以看到HEAD版本在這裏:http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/util/concurrent/ListenableFuture.html

的裝飾方法,你感興趣的是MoreExecutors.listeningDecorator

+0

謝謝克里斯,我使用'Futures.makeListenable(未來未來)'直到R10可以(通過的Maven ;-))。我在一個循環中使用它,儘管我認爲使用靜態包裝器方法是不可能的。起初我找不到「ListenableExecutorService」或適當的方法。再次感謝。 – Johannes