java8线程池
//java8线程池 ExecutorService pool = Executors.newFixedThreadPool(4); Callable a = ()->{return findA();}; Callable b = ()->{return findB();}; Callable c = ()->{return findC();}; Callable d = ()->{return findD();}; FutureTask<List> fa = new FutureTask<List>(a); FutureTask<List> fb = new FutureTask<List>(b); FutureTask<List> fc = new FutureTask<List>(c); FutureTask<List> fd = new FutureTask<List>(d); Thread t1 = new Thread(fa); Thread t2 = new Thread(fb); Thread t3 = new Thread(fc); Thread t4 = new Thread(fd); pool.execute(t1); pool.execute(t2); pool.execute(t3); pool.execute(t4); pool.shutdown(); map.put("a",fa.get()); map.put("b",fb.get()); map.put("c",fc.get()); map.put("d",fd.get()); return map;
作者:四叶草的诗雨
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.