package cn.alittle.Main.Thread;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class ThreadPool {
public static void main(String[] args) throws InterruptedException, ExecutionException {
ExecutorService pool = Executors.newFixedThreadPool(2);
// ThreadPrint threadPrint = new ThreadPrint();
ThreadReturn th1 = new ThreadReturn(4);
ThreadReturn th2 = new ThreadReturn(10);
// pool.submit(threadPrint);
// pool.submit(threadPrint);
// pool.shutdown();
Future<Integer> p1 = pool.submit(th1);
Future<Integer> p2 = pool.submit(th2);
Integer val1 = p1.get();
Integer val2 = p2.get();
pool.shutdown();
System.out.println(val1+"-----"+val2);
}
}
网友评论