import java.util.*;
import java.util.concurrent.*;
public static void main(String[] args) throws Exception {
ExecutorService exe = Executors.newFixedThreadPool(12);
for (int i = 1; i <= 5; i++) {
exe.execute(new Runnable(){
@Override
public void run() {
try {
Thread.sleep(new Random().nextInt(10)*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("当前线程:" + Thread.currentThread().getName() + ",打印随机数:" + new Random().nextInt(1000));
}
});
}
exe.shutdown();
while (true) {
if (exe.isTerminated()) {
System.out.println("结束了!");
break;
}
Thread.sleep(1000);
}
}
检查线程池中是否还有线程
猜你喜欢
转载自blog.csdn.net/qidaorenzhe/article/details/102667027
今日推荐
周排行