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

判断线程池所有任务是否执行完毕

时间:2017-11-13 21:28:10      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:com   cat   pool   public   ble   sys   .sh   generate   inter   

package com.yd.wmsc.util;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;


public class Test {   
      
    public static void main(String[] args) throws IOException, InterruptedException {   
        ExecutorService service = Executors.newFixedThreadPool(2);   
        for (int i = 0; i < 4; i++) {   
            Runnable run = new Runnable() {   
                @Override  
                public void run() {   
                   try {
                    Thread.currentThread().sleep(10000);
                    System.out.println("1");
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                };
                }   
            };   
            service.execute(run);   
        }   
        service.shutdown();   
        service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);   
        System.out.println("all thread complete");   
    }   
} 

 

判断线程池所有任务是否执行完毕

标签:com   cat   pool   public   ble   sys   .sh   generate   inter   

原文地址:http://www.cnblogs.com/tonggc1668/p/7827668.html

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