public class MainTest {
public static void main(String[] args) {
ExecutorService threadPool = Executors.newFixedThreadPool(5);
for(int i = 0; i < 100000; i++) {
threadPool.execute(new Command());
}
while(true) {
try {
Thread.sleep(10);
}
catch (InterruptedException e) {
e.printStackTrace();
}
if(Resource.getTotal() == 100000) {
threadPool.shutdown();
break;
}
}
}
}
主线程无线循环判断,当总数到达100000的时候,终止线程池,然后程序终止。
慕哥6287543
守着一只汪
元芳怎么了