【发布时间】:2017-07-12 04:17:21
【问题描述】:
这是有效的代码,但我明确指定了等待时间。当所有线程都完成执行时,有什么方法可以退出ExecutorService。
ExecutorService es = Executors.newCachedThreadPool();
{
for(final List<String> list:partitions){
es.execute(new Runnable() {
public void run() {
try{
System.out.println(list);
new CallAPI().make_call(list, access_token);
}catch(Exception e){
System.out.println(e);
}
}
});
Thread.sleep(5000);
}
boolean finshed = es.awaitTermination(15, TimeUnit.MINUTES);
es.shutdown();
boolean finshed = es.awaitTermination(15, TimeUnit.MINUTES);==>我在这里给了等待时间,但我不想要这个,因为我不知道线程什么时候完成执行
【问题讨论】:
-
shutdown 和 awaitTermination 的顺序是错误的
标签: java multithreading executorservice executor