what is the best way to wait ThreadPoolExecutor finish thread in java?

Viewed 2206

I an using ThreadPoolExecutor in java to excute multi threads, and I have to do something after threads finish, and have to wait.

So I want to ask what is the best way to do that?

Is that right I do in the way?

threadPool.shutdown();

boolean loop = true;
Integer x = threadPool.getPoolSize();
while (threadPool.getPoolSize() != 0) {
}
2 Answers
Related