ThreadPoolExecutor executor = new ThreadPoolExecutor(5,5, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
int n = threads.size();
for(int i=0; i<n; i++) {
executor.execute(threads.get(i));
}
executor.shutdown();
try {
boolean loop = true;
do { //等待所有任务完成
loop = !executor.awaitTermination(2, TimeUnit.SECONDS);
} while(loop);
} catch (InterruptedException e) {
}
long end = System.currentTimeMillis();
System.out.println("我是System.out.println,5个线程共运行了那么多的时间:" + (end - begin));