java8线程池
2021-04-02 00:33
标签:call find return span java8 线程 bsp get cut java8线程池 标签:call find return span java8 线程 bsp get cut 原文地址:https://www.cnblogs.com/name-lizonglin/p/13503159.html //java8线程池
ExecutorService pool = Executors.newFixedThreadPool(4);
Callable a = ()->{return findA();};
Callable b = ()->{return findB();};
Callable c = ()->{return findC();};
Callable d = ()->{return findD();};
FutureTask
fa = new FutureTask
(a);
FutureTask
fb = new FutureTask
(b);
FutureTask
fc = new FutureTask
(c);
FutureTask
fd = new FutureTask
(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;