码迷,mamicode.com
首页 > 编程语言 > 详细

java8线程池

时间:2020-08-17 17:10:01      阅读:59      评论:0      收藏:0      [点我收藏+]

标签:call   find   return   span   java8   线程   bsp   get   cut   

       //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;

 

java8线程池

标签:call   find   return   span   java8   线程   bsp   get   cut   

原文地址:https://www.cnblogs.com/name-lizonglin/p/13503159.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!