其他分享
首页 > 其他分享> > 线程安全的集合:CopyOnWriteArrayList

线程安全的集合:CopyOnWriteArrayList

作者:互联网

public class TestJUC {
  public static void main(String[] args) {
    CopyOnWriteArrayList<String> list=new CopyOnWriteArrayList<>();
    for (int i = 0; i < 10000; i++) {
      new Thread(()->{
        list.add(Thread.currentThread().getName());
      }).start();
    }
      try {
        Thread.sleep(3000);
      } catch (InterruptedException e) {
        e.printStackTrace();
    }
      System.out.println(list.size());
    }
}

标签:Thread,list,CopyOnWriteArrayList,线程,集合,new,public,size
来源: https://www.cnblogs.com/zhengqingbo/p/15073562.html