Skip to content

Instantly share code, notes, and snippets.

@vector4wang
Created July 2, 2019 06:01
Show Gist options
  • Save vector4wang/bf7e45f2d974b473b4c4a7840a93da1b to your computer and use it in GitHub Desktop.
Save vector4wang/bf7e45f2d974b473b4c4a7840a93da1b to your computer and use it in GitHub Desktop.
[Java 线程池 等待执行] #Java #线程池
ExecutorService executor = Executors.newFixedThreadPool(45);
for(...){
executor.execute(()->{
// do something
});
}
try {
// awaitTermination返回false即超时会继续循环,返回true即线程池中的线程执行完成主线程跳出循环往下执行,每隔10秒循环一次
while (!executor.awaitTermination(10, TimeUnit.SECONDS)){}
} catch (Exception e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment