首页 > 学院 > 开发设计 > 正文

Future 返回list

2019-11-08 02:36:59
字体:
来源:转载
供稿:网友
 ExecutorService pool  = Executors.newFixedThreadPool(3);        List<Future<JestClient>> list = Lists.newArrayList();        for(int i=0;i<4;i++){            Future<JestClient> submit = pool.submit(new Callable<JestClient>() {                public JestClient call() throws Exception {                    JestClient client = EsFactory.getClient();                    System.out.PRintln(Thread.currentThread().getName() + "--->" + System.currentTimeMillis() + "---" + client);                    return client;                }            });            list.add(submit);        }        for(Future<JestClient> fut:list){            System.out.println(Thread.currentThread().getName()+"---"+fut.get());        }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表