Java 如何判断线程池所有任务是否执行完毕

2025-01-19 12:49:10
推荐回答(1个)
回答1:

  import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test {

public static void main(String args[]) throws InterruptedException {
ExecutorService exe = Executors.newFixedThreadPool(50);
for (int i = 1; i <= 5; i++) {
exe.execute(new SubThread(i));
}
exe.shutdown();
while (true) {
if (exe.isTerminated()) {
System.out.println("结束了!");
break;
}
Thread.sleep(200);
}
}
}