public void main( List<String> list) {
List<String> a=new ArrayList<>();
//自定义线程池
ExecutorService pool=new ThreadPoolExecutor(5,10,
1L, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(3),
Executors.defaultThreadFactory(),
new ThreadPoolExecutor.AbortPolicy());
final CountDownLatch endGate = new CountDownLatch(list.size());
for (int i = 0; i < list.size(); i++) {
String str = list.get(i);
Runnable run = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
//具体操作
} catch (Exception e) {
e.printStackTrace();
}finally {
endGate.countDown();
}
}
};
pool.execute(run);
//pool.submit(run);
}
try {
endGate.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
pool.shutdown();
System.out.println("结束!");
return a;
}