Created
July 2, 2019 06:01
-
-
Save vector4wang/bf7e45f2d974b473b4c4a7840a93da1b to your computer and use it in GitHub Desktop.
[Java 线程池 等待执行] #Java #线程池
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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