ListenableFuture demo
来源:互联网 发布:数字滤波算法快速滤波 编辑:程序博客网 时间:2024/05/29 09:11
import java.util.Arrays;import java.util.List;import java.util.concurrent.Callable;import java.util.concurrent.ExecutionException;import java.util.concurrent.Executors;import com.google.common.collect.Lists;import com.google.common.util.concurrent.Futures;import com.google.common.util.concurrent.ListenableFuture;import com.google.common.util.concurrent.ListeningExecutorService;import com.google.common.util.concurrent.MoreExecutors;import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;public class ListenableFutureTest2 {public static void main(String[] args) throws InterruptedException,ExecutionException {ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1));final ListenableFuture<String> future = executor.submit(new Callable<String>() {public String call() throws Exception {return "Hello listenable future";}});final ListenableFuture<String> future2 = executor.submit(new Callable<String>() {public String call() throws Exception {Thread.sleep(10000);return "Hello listenable future2";}});List<ListenableFuture<String>> futures = Lists.newArrayList();futures.add(future);futures.add(future2);ListenableFuture<List<String>> futureAll = Futures.successfulAsList(futures);System.out.println(Arrays.toString(futureAll.get().toArray()));System.out.println("exit..");}}
0 0
- ListenableFuture demo
- ListenableFuture demo
- ListenableFuture
- ListenableFuture
- ListenableFuture
- guava ListenableFuture
- guava ListenableFuture
- ListenableFuture in Guava
- guava ListenableFuture使用
- ListenableFuture in Guava
- Google Guava ListenableFuture入门
- Guava 中的 ListenableFuture
- Guava ListenableFuture 小试牛刀
- ListenableFuture in Guava
- guava中的ListenableFuture
- ListenableFuture in Guava
- guava的ListenableFuture使用
- 多线程Future之Guava ListenableFuture
- mybatis批量操作
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in
- word 文档中嵌入和链接OLE 对象|Packager-对象包装程序
- 崩溃统计
- Jenkins入门系列之——02第二章 Jenkins安装与配置
- ListenableFuture demo
- java第二十一节-字节流FileOutputStream-写
- Elasticsearch的Mapping之元数据类型
- iOS CALayer中position和anchorPoint的联系和区别
- js点击空白处隐藏div
- 几款开源的图形化Redis客户端管理软件
- ubuntu 14.04配置XGboost
- 查找有序旋转数组中的最小值
- Java数据类型和MySql数据类型对应表