首页 > 编程语言 > 详细

多线程之(Executor)二

时间:2014-04-16 14:20:57      阅读:635      评论:0      收藏:0      [点我收藏+]



package multiThread;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class Demon2 {
    public static void main(String[] args) {
        ExecutorService exe = Executors.newFixedThreadPool(10);
          
        Future<String> future = exe.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(10000);
                return "hello thread";
            }
              
        });
          
        try {
            System.out.println(future.get(1000, TimeUnit.MILLISECONDS));
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        } finally {
            exe.shutdown();
        }
    }
}


多线程之(Executor)二,布布扣,bubuko.com

多线程之(Executor)二

原文:http://chenjizhan.blog.51cto.com/2577729/1395694

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!