美文网首页
带返回值的线程池

带返回值的线程池

作者: 白纸糊 | 来源:发表于2019-03-27 16:15 被阅读0次
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);
    
    }

}

相关文章

网友评论

      本文标题:带返回值的线程池

      本文链接:https://www.haomeiwen.com/subject/pmazvqtx.html