JUC安全类型的集合

package syn;

import java.util.concurrent.CopyOnWriteArrayList;
//测试JUC安全类型的集合
public class TestJUC {

public static void main(String[] args) throws InterruptedException {
CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
for (int i = 0; i < 10000; i++) {
new Thread(()->{
list.add(Thread.currentThread().getName());
}).start();
Thread.sleep(1000);
}
System.out.println(list.size());
}
}
上一篇:【JUC编程】线程的创建(三)


下一篇:JUC并发学习笔记