public static void main(String[] args) {
long startTime = System.currentTimeMillis();
Set<String> str = new CopyOnWriteArraySet<String>();
ExecutorService executorService = Executors.newFixedThreadPool(57);
for(int i=0;i<10000;i++){
int finalI = i;
executorService.submit(()->{
try {
Thread.sleep(1l);
} catch (InterruptedException e) {
e.printStackTrace();
}
//System.out.println("huqi"+finalI+Thread.currentThread().getName());
str.add("huqi"+ finalI);
});
}
// 顺序的停止线程
executorService.shutdown();
//判断是否所有的线程已经运行完
while (!executorService.isTerminated()) {
try {
executorService.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println(str.size());
System.out.println(endTime-startTime);
}